From 41d2272711255f5a25e16e3507ec3318bc550189 Mon Sep 17 00:00:00 2001 From: Brandon Lum Date: Mon, 6 Jun 2022 10:42:27 -0400 Subject: [PATCH 1/2] convert spdx structs to versioned pkgs Signed-off-by: Brandon Lum --- spdx/annotation.go | 92 --------- spdx/common/annotation.go | 44 ++++ spdx/{ => common}/checksum.go | 2 +- spdx/common/creation_info.go | 44 ++++ spdx/{ => common}/identifier.go | 2 +- spdx/common/package.go | 105 ++++++++++ spdx/common/snippet.go | 20 ++ spdx/creation_info.go | 86 -------- spdx/document.go | 122 ----------- spdx/file.go | 177 ---------------- spdx/other_license.go | 59 ------ spdx/package.go | 348 -------------------------------- spdx/relationship.go | 39 ---- spdx/review.go | 47 ----- spdx/snippet.go | 102 ---------- spdx/v2_1/annotation.go | 29 +++ spdx/v2_1/creation_info.go | 26 +++ spdx/v2_1/document.go | 65 ++++++ spdx/v2_1/file.go | 90 +++++++++ spdx/v2_1/other_license.go | 31 +++ spdx/v2_1/package.go | 120 +++++++++++ spdx/v2_1/relationship.go | 23 +++ spdx/v2_1/review.go | 25 +++ spdx/v2_1/snippet.go | 44 ++++ spdx/v2_2/annotation.go | 29 +++ spdx/v2_2/creation_info.go | 26 +++ spdx/v2_2/document.go | 65 ++++++ spdx/v2_2/file.go | 94 +++++++++ spdx/v2_2/other_license.go | 31 +++ spdx/v2_2/package.go | 133 ++++++++++++ spdx/v2_2/relationship.go | 23 +++ spdx/v2_2/review.go | 25 +++ spdx/v2_2/snippet.go | 48 +++++ 33 files changed, 1142 insertions(+), 1074 deletions(-) delete mode 100644 spdx/annotation.go create mode 100644 spdx/common/annotation.go rename spdx/{ => common}/checksum.go (98%) create mode 100644 spdx/common/creation_info.go rename spdx/{ => common}/identifier.go (99%) create mode 100644 spdx/common/package.go create mode 100644 spdx/common/snippet.go delete mode 100644 spdx/creation_info.go delete mode 100644 spdx/document.go delete mode 100644 spdx/file.go delete mode 100644 spdx/other_license.go delete mode 100644 spdx/package.go delete mode 100644 spdx/relationship.go delete mode 100644 spdx/review.go delete mode 100644 spdx/snippet.go create mode 100644 spdx/v2_1/annotation.go create mode 100644 spdx/v2_1/creation_info.go create mode 100644 spdx/v2_1/document.go create mode 100644 spdx/v2_1/file.go create mode 100644 spdx/v2_1/other_license.go create mode 100644 spdx/v2_1/package.go create mode 100644 spdx/v2_1/relationship.go create mode 100644 spdx/v2_1/review.go create mode 100644 spdx/v2_1/snippet.go create mode 100644 spdx/v2_2/annotation.go create mode 100644 spdx/v2_2/creation_info.go create mode 100644 spdx/v2_2/document.go create mode 100644 spdx/v2_2/file.go create mode 100644 spdx/v2_2/other_license.go create mode 100644 spdx/v2_2/package.go create mode 100644 spdx/v2_2/relationship.go create mode 100644 spdx/v2_2/review.go create mode 100644 spdx/v2_2/snippet.go diff --git a/spdx/annotation.go b/spdx/annotation.go deleted file mode 100644 index 560b6f00..00000000 --- a/spdx/annotation.go +++ /dev/null @@ -1,92 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - -package spdx - -import ( - "encoding/json" - "fmt" - "strings" -) - -type Annotator struct { - Annotator string - // including AnnotatorType: one of "Person", "Organization" or "Tool" - AnnotatorType string -} - -// UnmarshalJSON takes an annotator in the typical one-line format and parses it into an Annotator struct. -// This function is also used when unmarshalling YAML -func (a *Annotator) UnmarshalJSON(data []byte) error { - // annotator will simply be a string - annotatorStr := string(data) - annotatorStr = strings.Trim(annotatorStr, "\"") - - annotatorFields := strings.SplitN(annotatorStr, ": ", 2) - - if len(annotatorFields) != 2 { - return fmt.Errorf("failed to parse Annotator '%s'", annotatorStr) - } - - a.AnnotatorType = annotatorFields[0] - a.Annotator = annotatorFields[1] - - return nil -} - -// MarshalJSON converts the receiver into a slice of bytes representing an Annotator in string form. -// This function is also used when marshalling to YAML -func (a Annotator) MarshalJSON() ([]byte, error) { - if a.Annotator != "" { - return json.Marshal(fmt.Sprintf("%s: %s", a.AnnotatorType, a.Annotator)) - } - - return []byte{}, nil -} - -// Annotation2_1 is an Annotation section of an SPDX Document for version 2.1 of the spec. -type Annotation2_1 struct { - // 8.1: Annotator - // Cardinality: conditional (mandatory, one) if there is an Annotation - Annotator Annotator `json:"annotator"` - - // 8.2: Annotation Date: YYYY-MM-DDThh:mm:ssZ - // Cardinality: conditional (mandatory, one) if there is an Annotation - AnnotationDate string `json:"annotationDate"` - - // 8.3: Annotation Type: "REVIEW" or "OTHER" - // Cardinality: conditional (mandatory, one) if there is an Annotation - AnnotationType string `json:"annotationType"` - - // 8.4: SPDX Identifier Reference - // Cardinality: conditional (mandatory, one) if there is an Annotation - // This field is not used in hierarchical data formats where the referenced element is clear, such as JSON or YAML. - AnnotationSPDXIdentifier DocElementID `json:"-"` - - // 8.5: Annotation Comment - // Cardinality: conditional (mandatory, one) if there is an Annotation - AnnotationComment string `json:"comment"` -} - -// Annotation2_2 is an Annotation section of an SPDX Document for version 2.2 of the spec. -type Annotation2_2 struct { - // 8.1: Annotator - // Cardinality: conditional (mandatory, one) if there is an Annotation - Annotator Annotator `json:"annotator"` - - // 8.2: Annotation Date: YYYY-MM-DDThh:mm:ssZ - // Cardinality: conditional (mandatory, one) if there is an Annotation - AnnotationDate string `json:"annotationDate"` - - // 8.3: Annotation Type: "REVIEW" or "OTHER" - // Cardinality: conditional (mandatory, one) if there is an Annotation - AnnotationType string `json:"annotationType"` - - // 8.4: SPDX Identifier Reference - // Cardinality: conditional (mandatory, one) if there is an Annotation - // This field is not used in hierarchical data formats where the referenced element is clear, such as JSON or YAML. - AnnotationSPDXIdentifier DocElementID `json:"-"` - - // 8.5: Annotation Comment - // Cardinality: conditional (mandatory, one) if there is an Annotation - AnnotationComment string `json:"comment"` -} diff --git a/spdx/common/annotation.go b/spdx/common/annotation.go new file mode 100644 index 00000000..e77d7b78 --- /dev/null +++ b/spdx/common/annotation.go @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package common + +import ( + "encoding/json" + "fmt" + "strings" +) + +type Annotator struct { + Annotator string + // including AnnotatorType: one of "Person", "Organization" or "Tool" + AnnotatorType string +} + +// UnmarshalJSON takes an annotator in the typical one-line format and parses it into an Annotator struct. +// This function is also used when unmarshalling YAML +func (a *Annotator) UnmarshalJSON(data []byte) error { + // annotator will simply be a string + annotatorStr := string(data) + annotatorStr = strings.Trim(annotatorStr, "\"") + + annotatorFields := strings.SplitN(annotatorStr, ": ", 2) + + if len(annotatorFields) != 2 { + return fmt.Errorf("failed to parse Annotator '%s'", annotatorStr) + } + + a.AnnotatorType = annotatorFields[0] + a.Annotator = annotatorFields[1] + + return nil +} + +// MarshalJSON converts the receiver into a slice of bytes representing an Annotator in string form. +// This function is also used when marshalling to YAML +func (a Annotator) MarshalJSON() ([]byte, error) { + if a.Annotator != "" { + return json.Marshal(fmt.Sprintf("%s: %s", a.AnnotatorType, a.Annotator)) + } + + return []byte{}, nil +} diff --git a/spdx/checksum.go b/spdx/common/checksum.go similarity index 98% rename from spdx/checksum.go rename to spdx/common/checksum.go index 3295969a..02a57fff 100644 --- a/spdx/checksum.go +++ b/spdx/common/checksum.go @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later -package spdx +package common // ChecksumAlgorithm represents the algorithm used to generate the file checksum in the Checksum struct. type ChecksumAlgorithm string diff --git a/spdx/common/creation_info.go b/spdx/common/creation_info.go new file mode 100644 index 00000000..c87ae7be --- /dev/null +++ b/spdx/common/creation_info.go @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package common + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Creator is a wrapper around the Creator SPDX field. The SPDX field contains two values, which requires special +// handling in order to marshal/unmarshal it to/from Go data types. +type Creator struct { + Creator string + // CreatorType should be one of "Person", "Organization", or "Tool" + CreatorType string +} + +// UnmarshalJSON takes an annotator in the typical one-line format and parses it into a Creator struct. +// This function is also used when unmarshalling YAML +func (c *Creator) UnmarshalJSON(data []byte) error { + str := string(data) + str = strings.Trim(str, "\"") + fields := strings.SplitN(str, ": ", 2) + + if len(fields) != 2 { + return fmt.Errorf("failed to parse Creator '%s'", str) + } + + c.CreatorType = fields[0] + c.Creator = fields[1] + + return nil +} + +// MarshalJSON converts the receiver into a slice of bytes representing a Creator in string form. +// This function is also used with marshalling to YAML +func (c Creator) MarshalJSON() ([]byte, error) { + if c.Creator != "" { + return json.Marshal(fmt.Sprintf("%s: %s", c.CreatorType, c.Creator)) + } + + return []byte{}, nil +} diff --git a/spdx/identifier.go b/spdx/common/identifier.go similarity index 99% rename from spdx/identifier.go rename to spdx/common/identifier.go index 56f8ffc8..d6568676 100644 --- a/spdx/identifier.go +++ b/spdx/common/identifier.go @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later -package spdx +package common import ( "encoding/json" diff --git a/spdx/common/package.go b/spdx/common/package.go new file mode 100644 index 00000000..e0635df2 --- /dev/null +++ b/spdx/common/package.go @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package common + +import ( + "encoding/json" + "fmt" + "strings" +) + +type Supplier struct { + // can be "NOASSERTION" + Supplier string + // SupplierType can be one of "Person", "Organization", or empty if Supplier is "NOASSERTION" + SupplierType string +} + +// UnmarshalJSON takes a supplier in the typical one-line format and parses it into a Supplier struct. +// This function is also used when unmarshalling YAML +func (s *Supplier) UnmarshalJSON(data []byte) error { + // the value is just a string presented as a slice of bytes + supplierStr := string(data) + supplierStr = strings.Trim(supplierStr, "\"") + + if supplierStr == "NOASSERTION" { + s.Supplier = supplierStr + return nil + } + + supplierFields := strings.SplitN(supplierStr, ": ", 2) + + if len(supplierFields) != 2 { + return fmt.Errorf("failed to parse Supplier '%s'", supplierStr) + } + + s.SupplierType = supplierFields[0] + s.Supplier = supplierFields[1] + + return nil +} + +// MarshalJSON converts the receiver into a slice of bytes representing a Supplier in string form. +// This function is also used when marshalling to YAML +func (s Supplier) MarshalJSON() ([]byte, error) { + if s.Supplier == "NOASSERTION" { + return json.Marshal(s.Supplier) + } else if s.SupplierType != "" && s.Supplier != "" { + return json.Marshal(fmt.Sprintf("%s: %s", s.SupplierType, s.Supplier)) + } + + return []byte{}, fmt.Errorf("failed to marshal invalid Supplier: %+v", s) +} + +type Originator struct { + // can be "NOASSERTION" + Originator string + // OriginatorType can be one of "Person", "Organization", or empty if Originator is "NOASSERTION" + OriginatorType string +} + +// UnmarshalJSON takes an originator in the typical one-line format and parses it into an Originator struct. +// This function is also used when unmarshalling YAML +func (o *Originator) UnmarshalJSON(data []byte) error { + // the value is just a string presented as a slice of bytes + originatorStr := string(data) + originatorStr = strings.Trim(originatorStr, "\"") + + if originatorStr == "NOASSERTION" { + o.Originator = originatorStr + return nil + } + + originatorFields := strings.SplitN(originatorStr, ": ", 2) + + if len(originatorFields) != 2 { + return fmt.Errorf("failed to parse Originator '%s'", originatorStr) + } + + o.OriginatorType = originatorFields[0] + o.Originator = originatorFields[1] + + return nil +} + +// MarshalJSON converts the receiver into a slice of bytes representing an Originator in string form. +// This function is also used when marshalling to YAML +func (o Originator) MarshalJSON() ([]byte, error) { + if o.Originator == "NOASSERTION" { + return json.Marshal(o.Originator) + } else if o.Originator != "" { + return json.Marshal(fmt.Sprintf("%s: %s", o.OriginatorType, o.Originator)) + } + + return []byte{}, nil +} + +type PackageVerificationCode struct { + // Cardinality: mandatory, one if filesAnalyzed is true / omitted; + // zero (must be omitted) if filesAnalyzed is false + Value string `json:"packageVerificationCodeValue"` + // Spec also allows specifying files to exclude from the + // verification code algorithm; intended to enable exclusion of + // the SPDX document file itself. + ExcludedFiles []string `json:"packageVerificationCodeExcludedFiles"` +} diff --git a/spdx/common/snippet.go b/spdx/common/snippet.go new file mode 100644 index 00000000..63afac3b --- /dev/null +++ b/spdx/common/snippet.go @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package common + +type SnippetRangePointer struct { + // 5.3: Snippet Byte Range: [start byte]:[end byte] + // Cardinality: mandatory, one + Offset int `json:"offset,omitempty"` + + // 5.4: Snippet Line Range: [start line]:[end line] + // Cardinality: optional, one + LineNumber int `json:"lineNumber,omitempty"` + + FileSPDXIdentifier ElementID `json:"reference"` +} + +type SnippetRange struct { + StartPointer SnippetRangePointer `json:"startPointer"` + EndPointer SnippetRangePointer `json:"endPointer"` +} diff --git a/spdx/creation_info.go b/spdx/creation_info.go deleted file mode 100644 index c0b6f636..00000000 --- a/spdx/creation_info.go +++ /dev/null @@ -1,86 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - -package spdx - -import ( - "encoding/json" - "fmt" - "strings" -) - -// Creator is a wrapper around the Creator SPDX field. The SPDX field contains two values, which requires special -// handling in order to marshal/unmarshal it to/from Go data types. -type Creator struct { - Creator string - // CreatorType should be one of "Person", "Organization", or "Tool" - CreatorType string -} - -// UnmarshalJSON takes an annotator in the typical one-line format and parses it into a Creator struct. -// This function is also used when unmarshalling YAML -func (c *Creator) UnmarshalJSON(data []byte) error { - str := string(data) - str = strings.Trim(str, "\"") - fields := strings.SplitN(str, ": ", 2) - - if len(fields) != 2 { - return fmt.Errorf("failed to parse Creator '%s'", str) - } - - c.CreatorType = fields[0] - c.Creator = fields[1] - - return nil -} - -// MarshalJSON converts the receiver into a slice of bytes representing a Creator in string form. -// This function is also used with marshalling to YAML -func (c Creator) MarshalJSON() ([]byte, error) { - if c.Creator != "" { - return json.Marshal(fmt.Sprintf("%s: %s", c.CreatorType, c.Creator)) - } - - return []byte{}, nil -} - -// CreationInfo2_1 is a Document Creation Information section of an -// SPDX Document for version 2.1 of the spec. -type CreationInfo2_1 struct { - // 2.7: License List Version - // Cardinality: optional, one - LicenseListVersion string `json:"licenseListVersion"` - - // 2.8: Creators: may have multiple keys for Person, Organization - // and/or Tool - // Cardinality: mandatory, one or many - Creators []Creator `json:"creators"` - - // 2.9: Created: data format YYYY-MM-DDThh:mm:ssZ - // Cardinality: mandatory, one - Created string `json:"created"` - - // 2.10: Creator Comment - // Cardinality: optional, one - CreatorComment string `json:"comment"` -} - -// CreationInfo2_2 is a Document Creation Information section of an -// SPDX Document for version 2.2 of the spec. -type CreationInfo2_2 struct { - // 2.7: License List Version - // Cardinality: optional, one - LicenseListVersion string `json:"licenseListVersion"` - - // 2.8: Creators: may have multiple keys for Person, Organization - // and/or Tool - // Cardinality: mandatory, one or many - Creators []Creator `json:"creators"` - - // 2.9: Created: data format YYYY-MM-DDThh:mm:ssZ - // Cardinality: mandatory, one - Created string `json:"created"` - - // 2.10: Creator Comment - // Cardinality: optional, one - CreatorComment string `json:"comment"` -} diff --git a/spdx/document.go b/spdx/document.go deleted file mode 100644 index a3117cb7..00000000 --- a/spdx/document.go +++ /dev/null @@ -1,122 +0,0 @@ -// Package spdx contains the struct definition for an SPDX Document -// and its constituent parts. -// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later -package spdx - -// ExternalDocumentRef2_1 is a reference to an external SPDX document -// as defined in section 2.6 for version 2.1 of the spec. -type ExternalDocumentRef2_1 struct { - // DocumentRefID is the ID string defined in the start of the - // reference. It should _not_ contain the "DocumentRef-" part - // of the mandatory ID string. - DocumentRefID string `json:"externalDocumentId"` - - // URI is the URI defined for the external document - URI string `json:"spdxDocument"` - - // Checksum is the actual hash data - Checksum Checksum `json:"checksum"` -} - -// ExternalDocumentRef2_2 is a reference to an external SPDX document -// as defined in section 2.6 for version 2.2 of the spec. -type ExternalDocumentRef2_2 struct { - // DocumentRefID is the ID string defined in the start of the - // reference. It should _not_ contain the "DocumentRef-" part - // of the mandatory ID string. - DocumentRefID string `json:"externalDocumentId"` - - // URI is the URI defined for the external document - URI string `json:"spdxDocument"` - - // Checksum is the actual hash data - Checksum Checksum `json:"checksum"` -} - -// Document2_1 is an SPDX Document for version 2.1 of the spec. -// See https://spdx.org/sites/cpstandard/files/pages/files/spdxversion2.1.pdf -type Document2_1 struct { - // 2.1: SPDX Version; should be in the format "SPDX-2.1" - // Cardinality: mandatory, one - SPDXVersion string `json:"spdxVersion"` - - // 2.2: Data License; should be "CC0-1.0" - // Cardinality: mandatory, one - DataLicense string `json:"dataLicense"` - - // 2.3: SPDX Identifier; should be "DOCUMENT" to represent - // mandatory identifier of SPDXRef-DOCUMENT - // Cardinality: mandatory, one - SPDXIdentifier ElementID `json:"SPDXID"` - - // 2.4: Document Name - // Cardinality: mandatory, one - DocumentName string `json:"name"` - - // 2.5: Document Namespace - // Cardinality: mandatory, one - DocumentNamespace string `json:"documentNamespace"` - - // 2.6: External Document References - // Cardinality: optional, one or many - ExternalDocumentReferences []ExternalDocumentRef2_1 `json:"externalDocumentRefs,omitempty"` - - // 2.11: Document Comment - // Cardinality: optional, one - DocumentComment string `json:"comment,omitempty"` - - CreationInfo *CreationInfo2_1 `json:"creationInfo"` - Packages []*Package2_1 `json:"packages"` - Files []*File2_1 `json:"files"` - OtherLicenses []*OtherLicense2_1 `json:"hasExtractedLicensingInfos"` - Relationships []*Relationship2_1 `json:"relationships"` - Annotations []*Annotation2_1 `json:"annotations"` - Snippets []Snippet2_1 `json:"snippets"` - - // DEPRECATED in version 2.0 of spec - Reviews []*Review2_1 -} - -// Document2_2 is an SPDX Document for version 2.2 of the spec. -// See https://spdx.github.io/spdx-spec/v2-draft/ (DRAFT) -type Document2_2 struct { - // 2.1: SPDX Version; should be in the format "SPDX-2.2" - // Cardinality: mandatory, one - SPDXVersion string `json:"spdxVersion"` - - // 2.2: Data License; should be "CC0-1.0" - // Cardinality: mandatory, one - DataLicense string `json:"dataLicense"` - - // 2.3: SPDX Identifier; should be "DOCUMENT" to represent - // mandatory identifier of SPDXRef-DOCUMENT - // Cardinality: mandatory, one - SPDXIdentifier ElementID `json:"SPDXID"` - - // 2.4: Document Name - // Cardinality: mandatory, one - DocumentName string `json:"name"` - - // 2.5: Document Namespace - // Cardinality: mandatory, one - DocumentNamespace string `json:"documentNamespace"` - - // 2.6: External Document References - // Cardinality: optional, one or many - ExternalDocumentReferences []ExternalDocumentRef2_2 `json:"externalDocumentRefs,omitempty"` - - // 2.11: Document Comment - // Cardinality: optional, one - DocumentComment string `json:"comment,omitempty"` - - CreationInfo *CreationInfo2_2 `json:"creationInfo"` - Packages []*Package2_2 `json:"packages"` - Files []*File2_2 `json:"files"` - OtherLicenses []*OtherLicense2_2 `json:"hasExtractedLicensingInfos"` - Relationships []*Relationship2_2 `json:"relationships"` - Annotations []*Annotation2_2 `json:"annotations"` - Snippets []Snippet2_2 `json:"snippets"` - - // DEPRECATED in version 2.0 of spec - Reviews []*Review2_2 -} diff --git a/spdx/file.go b/spdx/file.go deleted file mode 100644 index 01dbb368..00000000 --- a/spdx/file.go +++ /dev/null @@ -1,177 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - -package spdx - -// File2_1 is a File section of an SPDX Document for version 2.1 of the spec. -type File2_1 struct { - // 4.1: File Name - // Cardinality: mandatory, one - FileName string `json:"fileName"` - - // 4.2: File SPDX Identifier: "SPDXRef-[idstring]" - // Cardinality: mandatory, one - FileSPDXIdentifier ElementID `json:"SPDXID"` - - // 4.3: File Types - // Cardinality: optional, multiple - FileTypes []string `json:"fileTypes,omitempty"` - - // 4.4: File Checksum: may have keys for SHA1, SHA256 and/or MD5 - // Cardinality: mandatory, one SHA1, others may be optionally provided - Checksums []Checksum `json:"checksums"` - - // 4.5: Concluded License: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - LicenseConcluded string `json:"licenseConcluded"` - - // 4.6: License Information in File: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one or many - LicenseInfoInFiles []string `json:"licenseInfoInFiles"` - - // 4.7: Comments on License - // Cardinality: optional, one - LicenseComments string `json:"licenseComments,omitempty"` - - // 4.8: Copyright Text: copyright notice(s) text, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - FileCopyrightText string `json:"copyrightText"` - - // DEPRECATED in version 2.1 of spec - // 4.9-4.11: Artifact of Project variables (defined below) - // Cardinality: optional, one or many - ArtifactOfProjects []*ArtifactOfProject2_1 `json:"-"` - - // 4.12: File Comment - // Cardinality: optional, one - FileComment string `json:"comment,omitempty"` - - // 4.13: File Notice - // Cardinality: optional, one - FileNotice string `json:"noticeText,omitempty"` - - // 4.14: File Contributor - // Cardinality: optional, one or many - FileContributors []string `json:"fileContributors,omitempty"` - - // DEPRECATED in version 2.0 of spec - // 4.15: File Dependencies - // Cardinality: optional, one or many - FileDependencies []string `json:"-"` - - // Snippets contained in this File - // Note that Snippets could be defined in a different Document! However, - // the only ones that _THIS_ document can contain are the ones that are - // defined here -- so this should just be an ElementID. - Snippets map[ElementID]*Snippet2_1 `json:"-"` - - Annotations []Annotation2_1 `json:"annotations"` -} - -// ArtifactOfProject2_1 is a DEPRECATED collection of data regarding -// a Package, as defined in sections 4.9-4.11 in version 2.1 of the spec. -type ArtifactOfProject2_1 struct { - - // DEPRECATED in version 2.1 of spec - // 4.9: Artifact of Project Name - // Cardinality: conditional, required if present, one per AOP - Name string - - // DEPRECATED in version 2.1 of spec - // 4.10: Artifact of Project Homepage: URL or "UNKNOWN" - // Cardinality: optional, one per AOP - HomePage string - - // DEPRECATED in version 2.1 of spec - // 4.11: Artifact of Project Uniform Resource Identifier - // Cardinality: optional, one per AOP - URI string -} - -// File2_2 is a File section of an SPDX Document for version 2.2 of the spec. -type File2_2 struct { - // 4.1: File Name - // Cardinality: mandatory, one - FileName string `json:"fileName"` - - // 4.2: File SPDX Identifier: "SPDXRef-[idstring]" - // Cardinality: mandatory, one - FileSPDXIdentifier ElementID `json:"SPDXID"` - - // 4.3: File Types - // Cardinality: optional, multiple - FileTypes []string `json:"fileTypes,omitempty"` - - // 4.4: File Checksum: may have keys for SHA1, SHA256 and/or MD5 - // Cardinality: mandatory, one SHA1, others may be optionally provided - Checksums []Checksum `json:"checksums"` - - // 4.5: Concluded License: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - LicenseConcluded string `json:"licenseConcluded"` - - // 4.6: License Information in File: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one or many - LicenseInfoInFiles []string `json:"licenseInfoInFiles"` - - // 4.7: Comments on License - // Cardinality: optional, one - LicenseComments string `json:"licenseComments,omitempty"` - - // 4.8: Copyright Text: copyright notice(s) text, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - FileCopyrightText string `json:"copyrightText"` - - // DEPRECATED in version 2.1 of spec - // 4.9-4.11: Artifact of Project variables (defined below) - // Cardinality: optional, one or many - ArtifactOfProjects []*ArtifactOfProject2_2 `json:"-"` - - // 4.12: File Comment - // Cardinality: optional, one - FileComment string `json:"comment,omitempty"` - - // 4.13: File Notice - // Cardinality: optional, one - FileNotice string `json:"noticeText,omitempty"` - - // 4.14: File Contributor - // Cardinality: optional, one or many - FileContributors []string `json:"fileContributors,omitempty"` - - // 4.15: File Attribution Text - // Cardinality: optional, one or many - FileAttributionTexts []string `json:"attributionTexts,omitempty"` - - // DEPRECATED in version 2.0 of spec - // 4.16: File Dependencies - // Cardinality: optional, one or many - FileDependencies []string `json:"-"` - - // Snippets contained in this File - // Note that Snippets could be defined in a different Document! However, - // the only ones that _THIS_ document can contain are this ones that are - // defined here -- so this should just be an ElementID. - Snippets map[ElementID]*Snippet2_2 `json:"-"` - - Annotations []Annotation2_2 `json:"annotations,omitempty"` -} - -// ArtifactOfProject2_2 is a DEPRECATED collection of data regarding -// a Package, as defined in sections 4.9-4.11 in version 2.2 of the spec. -type ArtifactOfProject2_2 struct { - - // DEPRECATED in version 2.1 of spec - // 4.9: Artifact of Project Name - // Cardinality: conditional, required if present, one per AOP - Name string - - // DEPRECATED in version 2.1 of spec - // 4.10: Artifact of Project Homepage: URL or "UNKNOWN" - // Cardinality: optional, one per AOP - HomePage string - - // DEPRECATED in version 2.1 of spec - // 4.11: Artifact of Project Uniform Resource Identifier - // Cardinality: optional, one per AOP - URI string -} diff --git a/spdx/other_license.go b/spdx/other_license.go deleted file mode 100644 index 6e43676b..00000000 --- a/spdx/other_license.go +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - -package spdx - -// OtherLicense2_1 is an Other License Information section of an -// SPDX Document for version 2.1 of the spec. -type OtherLicense2_1 struct { - // 6.1: License Identifier: "LicenseRef-[idstring]" - // Cardinality: conditional (mandatory, one) if license is not - // on SPDX License List - LicenseIdentifier string `json:"licenseId"` - - // 6.2: Extracted Text - // Cardinality: conditional (mandatory, one) if there is a - // License Identifier assigned - ExtractedText string `json:"extractedText"` - - // 6.3: License Name: single line of text or "NOASSERTION" - // Cardinality: conditional (mandatory, one) if license is not - // on SPDX License List - LicenseName string `json:"name,omitempty"` - - // 6.4: License Cross Reference - // Cardinality: conditional (optional, one or many) if license - // is not on SPDX License List - LicenseCrossReferences []string `json:"seeAlsos,omitempty"` - - // 6.5: License Comment - // Cardinality: optional, one - LicenseComment string `json:"comment,omitempty"` -} - -// OtherLicense2_2 is an Other License Information section of an -// SPDX Document for version 2.2 of the spec. -type OtherLicense2_2 struct { - // 6.1: License Identifier: "LicenseRef-[idstring]" - // Cardinality: conditional (mandatory, one) if license is not - // on SPDX License List - LicenseIdentifier string `json:"licenseId"` - - // 6.2: Extracted Text - // Cardinality: conditional (mandatory, one) if there is a - // License Identifier assigned - ExtractedText string `json:"extractedText"` - - // 6.3: License Name: single line of text or "NOASSERTION" - // Cardinality: conditional (mandatory, one) if license is not - // on SPDX License List - LicenseName string `json:"name,omitempty"` - - // 6.4: License Cross Reference - // Cardinality: conditional (optional, one or many) if license - // is not on SPDX License List - LicenseCrossReferences []string `json:"seeAlsos,omitempty"` - - // 6.5: License Comment - // Cardinality: optional, one - LicenseComment string `json:"comment,omitempty"` -} diff --git a/spdx/package.go b/spdx/package.go deleted file mode 100644 index e6c45223..00000000 --- a/spdx/package.go +++ /dev/null @@ -1,348 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - -package spdx - -import ( - "encoding/json" - "fmt" - "strings" -) - -type Supplier struct { - // can be "NOASSERTION" - Supplier string - // SupplierType can be one of "Person", "Organization", or empty if Supplier is "NOASSERTION" - SupplierType string -} - -// UnmarshalJSON takes a supplier in the typical one-line format and parses it into a Supplier struct. -// This function is also used when unmarshalling YAML -func (s *Supplier) UnmarshalJSON(data []byte) error { - // the value is just a string presented as a slice of bytes - supplierStr := string(data) - supplierStr = strings.Trim(supplierStr, "\"") - - if supplierStr == "NOASSERTION" { - s.Supplier = supplierStr - return nil - } - - supplierFields := strings.SplitN(supplierStr, ": ", 2) - - if len(supplierFields) != 2 { - return fmt.Errorf("failed to parse Supplier '%s'", supplierStr) - } - - s.SupplierType = supplierFields[0] - s.Supplier = supplierFields[1] - - return nil -} - -// MarshalJSON converts the receiver into a slice of bytes representing a Supplier in string form. -// This function is also used when marshalling to YAML -func (s Supplier) MarshalJSON() ([]byte, error) { - if s.Supplier == "NOASSERTION" { - return json.Marshal(s.Supplier) - } else if s.SupplierType != "" && s.Supplier != "" { - return json.Marshal(fmt.Sprintf("%s: %s", s.SupplierType, s.Supplier)) - } - - return []byte{}, fmt.Errorf("failed to marshal invalid Supplier: %+v", s) -} - -type Originator struct { - // can be "NOASSERTION" - Originator string - // OriginatorType can be one of "Person", "Organization", or empty if Originator is "NOASSERTION" - OriginatorType string -} - -// UnmarshalJSON takes an originator in the typical one-line format and parses it into an Originator struct. -// This function is also used when unmarshalling YAML -func (o *Originator) UnmarshalJSON(data []byte) error { - // the value is just a string presented as a slice of bytes - originatorStr := string(data) - originatorStr = strings.Trim(originatorStr, "\"") - - if originatorStr == "NOASSERTION" { - o.Originator = originatorStr - return nil - } - - originatorFields := strings.SplitN(originatorStr, ": ", 2) - - if len(originatorFields) != 2 { - return fmt.Errorf("failed to parse Originator '%s'", originatorStr) - } - - o.OriginatorType = originatorFields[0] - o.Originator = originatorFields[1] - - return nil -} - -// MarshalJSON converts the receiver into a slice of bytes representing an Originator in string form. -// This function is also used when marshalling to YAML -func (o Originator) MarshalJSON() ([]byte, error) { - if o.Originator == "NOASSERTION" { - return json.Marshal(o.Originator) - } else if o.Originator != "" { - return json.Marshal(fmt.Sprintf("%s: %s", o.OriginatorType, o.Originator)) - } - - return []byte{}, nil -} - -type PackageVerificationCode struct { - // Cardinality: mandatory, one if filesAnalyzed is true / omitted; - // zero (must be omitted) if filesAnalyzed is false - Value string `json:"packageVerificationCodeValue"` - // Spec also allows specifying files to exclude from the - // verification code algorithm; intended to enable exclusion of - // the SPDX document file itself. - ExcludedFiles []string `json:"packageVerificationCodeExcludedFiles"` -} - -// Package2_1 is a Package section of an SPDX Document for version 2.1 of the spec. -type Package2_1 struct { - // 3.1: Package Name - // Cardinality: mandatory, one - PackageName string `json:"name"` - - // 3.2: Package SPDX Identifier: "SPDXRef-[idstring]" - // Cardinality: mandatory, one - PackageSPDXIdentifier ElementID `json:"SPDXID"` - - // 3.3: Package Version - // Cardinality: optional, one - PackageVersion string `json:"versionInfo,omitempty"` - - // 3.4: Package File Name - // Cardinality: optional, one - PackageFileName string `json:"packageFileName,omitempty"` - - // 3.5: Package Supplier: may have single result for either Person or Organization, - // or NOASSERTION - // Cardinality: optional, one - PackageSupplier *Supplier `json:"supplier,omitempty"` - - // 3.6: Package Originator: may have single result for either Person or Organization, - // or NOASSERTION - // Cardinality: optional, one - PackageOriginator *Originator `json:"originator,omitempty"` - - // 3.7: Package Download Location - // Cardinality: mandatory, one - PackageDownloadLocation string `json:"downloadLocation"` - - // 3.8: FilesAnalyzed - // Cardinality: optional, one; default value is "true" if omitted - FilesAnalyzed bool `json:"filesAnalyzed,omitempty"` - // NOT PART OF SPEC: did FilesAnalyzed tag appear? - IsFilesAnalyzedTagPresent bool `json:"-"` - - // 3.9: Package Verification Code - PackageVerificationCode PackageVerificationCode `json:"packageVerificationCode"` - - // 3.10: Package Checksum: may have keys for SHA1, SHA256 and/or MD5 - // Cardinality: optional, one or many - PackageChecksums []Checksum `json:"checksums,omitempty"` - - // 3.11: Package Home Page - // Cardinality: optional, one - PackageHomePage string `json:"homepage,omitempty"` - - // 3.12: Source Information - // Cardinality: optional, one - PackageSourceInfo string `json:"sourceInfo,omitempty"` - - // 3.13: Concluded License: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - PackageLicenseConcluded string `json:"licenseConcluded"` - - // 3.14: All Licenses Info from Files: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one or many if filesAnalyzed is true / omitted; - // zero (must be omitted) if filesAnalyzed is false - PackageLicenseInfoFromFiles []string `json:"licenseInfoFromFiles"` - - // 3.15: Declared License: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - PackageLicenseDeclared string `json:"licenseDeclared"` - - // 3.16: Comments on License - // Cardinality: optional, one - PackageLicenseComments string `json:"licenseComments,omitempty"` - - // 3.17: Copyright Text: copyright notice(s) text, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - PackageCopyrightText string `json:"copyrightText"` - - // 3.18: Package Summary Description - // Cardinality: optional, one - PackageSummary string `json:"summary,omitempty"` - - // 3.19: Package Detailed Description - // Cardinality: optional, one - PackageDescription string `json:"description,omitempty"` - - // 3.20: Package Comment - // Cardinality: optional, one - PackageComment string `json:"comment,omitempty"` - - // 3.21: Package External Reference - // Cardinality: optional, one or many - PackageExternalReferences []*PackageExternalReference2_1 `json:"externalRefs,omitempty"` - - // Files contained in this Package - Files []*File2_1 - - Annotations []Annotation2_1 `json:"annotations,omitempty"` -} - -// PackageExternalReference2_1 is an External Reference to additional info -// about a Package, as defined in section 3.21 in version 2.1 of the spec. -type PackageExternalReference2_1 struct { - // category is "SECURITY", "PACKAGE-MANAGER" or "OTHER" - Category string `json:"referenceCategory"` - - // type is an [idstring] as defined in Appendix VI; - // called RefType here due to "type" being a Golang keyword - RefType string `json:"referenceType"` - - // locator is a unique string to access the package-specific - // info, metadata or content within the target location - Locator string `json:"referenceLocator"` - - // 3.22: Package External Reference Comment - // Cardinality: conditional (optional, one) for each External Reference - ExternalRefComment string `json:"comment"` -} - -// Package2_2 is a Package section of an SPDX Document for version 2.2 of the spec. -type Package2_2 struct { - // NOT PART OF SPEC - // flag: does this "package" contain files that were in fact "unpackaged", - // e.g. included directly in the Document without being in a Package? - IsUnpackaged bool - - // 3.1: Package Name - // Cardinality: mandatory, one - PackageName string `json:"name"` - - // 3.2: Package SPDX Identifier: "SPDXRef-[idstring]" - // Cardinality: mandatory, one - PackageSPDXIdentifier ElementID `json:"SPDXID"` - - // 3.3: Package Version - // Cardinality: optional, one - PackageVersion string `json:"versionInfo,omitempty"` - - // 3.4: Package File Name - // Cardinality: optional, one - PackageFileName string `json:"packageFileName,omitempty"` - - // 3.5: Package Supplier: may have single result for either Person or Organization, - // or NOASSERTION - // Cardinality: optional, one - PackageSupplier *Supplier `json:"supplier,omitempty"` - - // 3.6: Package Originator: may have single result for either Person or Organization, - // or NOASSERTION - // Cardinality: optional, one - PackageOriginator *Originator `json:"originator,omitempty"` - - // 3.7: Package Download Location - // Cardinality: mandatory, one - PackageDownloadLocation string `json:"downloadLocation"` - - // 3.8: FilesAnalyzed - // Cardinality: optional, one; default value is "true" if omitted - FilesAnalyzed bool `json:"filesAnalyzed,omitempty"` - // NOT PART OF SPEC: did FilesAnalyzed tag appear? - IsFilesAnalyzedTagPresent bool - - // 3.9: Package Verification Code - PackageVerificationCode PackageVerificationCode `json:"packageVerificationCode"` - - // 3.10: Package Checksum: may have keys for SHA1, SHA256 and/or MD5 - // Cardinality: optional, one or many - PackageChecksums []Checksum `json:"checksums"` - - // 3.11: Package Home Page - // Cardinality: optional, one - PackageHomePage string `json:"homepage,omitempty"` - - // 3.12: Source Information - // Cardinality: optional, one - PackageSourceInfo string `json:"sourceInfo,omitempty"` - - // 3.13: Concluded License: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - PackageLicenseConcluded string `json:"licenseConcluded"` - - // 3.14: All Licenses Info from Files: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one or many if filesAnalyzed is true / omitted; - // zero (must be omitted) if filesAnalyzed is false - PackageLicenseInfoFromFiles []string `json:"licenseInfoFromFiles"` - - // 3.15: Declared License: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - PackageLicenseDeclared string `json:"licenseDeclared"` - - // 3.16: Comments on License - // Cardinality: optional, one - PackageLicenseComments string `json:"licenseComments,omitempty"` - - // 3.17: Copyright Text: copyright notice(s) text, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - PackageCopyrightText string `json:"copyrightText"` - - // 3.18: Package Summary Description - // Cardinality: optional, one - PackageSummary string `json:"summary,omitempty"` - - // 3.19: Package Detailed Description - // Cardinality: optional, one - PackageDescription string `json:"description,omitempty"` - - // 3.20: Package Comment - // Cardinality: optional, one - PackageComment string `json:"comment,omitempty"` - - // 3.21: Package External Reference - // Cardinality: optional, one or many - PackageExternalReferences []*PackageExternalReference2_2 `json:"externalRefs,omitempty"` - - // 3.22: Package External Reference Comment - // Cardinality: conditional (optional, one) for each External Reference - // contained within PackageExternalReference2_1 struct, if present - - // 3.23: Package Attribution Text - // Cardinality: optional, one or many - PackageAttributionTexts []string `json:"attributionTexts,omitempty"` - - // Files contained in this Package - Files []*File2_2 - - Annotations []Annotation2_2 `json:"annotations"` -} - -// PackageExternalReference2_2 is an External Reference to additional info -// about a Package, as defined in section 3.21 in version 2.2 of the spec. -type PackageExternalReference2_2 struct { - // category is "SECURITY", "PACKAGE-MANAGER" or "OTHER" - Category string `json:"referenceCategory"` - - // type is an [idstring] as defined in Appendix VI; - // called RefType here due to "type" being a Golang keyword - RefType string `json:"referenceType"` - - // locator is a unique string to access the package-specific - // info, metadata or content within the target location - Locator string `json:"referenceLocator"` - - // 3.22: Package External Reference Comment - // Cardinality: conditional (optional, one) for each External Reference - ExternalRefComment string `json:"comment"` -} diff --git a/spdx/relationship.go b/spdx/relationship.go deleted file mode 100644 index 91277277..00000000 --- a/spdx/relationship.go +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - -package spdx - -// Relationship2_1 is a Relationship section of an SPDX Document for -// version 2.1 of the spec. -type Relationship2_1 struct { - - // 7.1: Relationship - // Cardinality: optional, one or more; one per Relationship2_1 - // one mandatory for SPDX Document with multiple packages - // RefA and RefB are first and second item - // Relationship is type from 7.1.1 - RefA DocElementID `json:"spdxElementId"` - RefB DocElementID `json:"relatedSpdxElement"` - Relationship string `json:"relationshipType"` - - // 7.2: Relationship Comment - // Cardinality: optional, one - RelationshipComment string `json:"comment,omitempty"` -} - -// Relationship2_2 is a Relationship section of an SPDX Document for -// version 2.2 of the spec. -type Relationship2_2 struct { - - // 7.1: Relationship - // Cardinality: optional, one or more; one per Relationship2_2 - // one mandatory for SPDX Document with multiple packages - // RefA and RefB are first and second item - // Relationship is type from 7.1.1 - RefA DocElementID `json:"spdxElementId"` - RefB DocElementID `json:"relatedSpdxElement"` - Relationship string `json:"relationshipType"` - - // 7.2: Relationship Comment - // Cardinality: optional, one - RelationshipComment string `json:"comment,omitempty"` -} diff --git a/spdx/review.go b/spdx/review.go deleted file mode 100644 index 8ca6a77c..00000000 --- a/spdx/review.go +++ /dev/null @@ -1,47 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - -package spdx - -// Review2_1 is a Review section of an SPDX Document for version 2.1 of the spec. -// DEPRECATED in version 2.0 of spec; retained here for compatibility. -type Review2_1 struct { - - // DEPRECATED in version 2.0 of spec - // 9.1: Reviewer - // Cardinality: optional, one - Reviewer string - // including AnnotatorType: one of "Person", "Organization" or "Tool" - ReviewerType string - - // DEPRECATED in version 2.0 of spec - // 9.2: Review Date: YYYY-MM-DDThh:mm:ssZ - // Cardinality: conditional (mandatory, one) if there is a Reviewer - ReviewDate string - - // DEPRECATED in version 2.0 of spec - // 9.3: Review Comment - // Cardinality: optional, one - ReviewComment string -} - -// Review2_2 is a Review section of an SPDX Document for version 2.2 of the spec. -// DEPRECATED in version 2.0 of spec; retained here for compatibility. -type Review2_2 struct { - - // DEPRECATED in version 2.0 of spec - // 9.1: Reviewer - // Cardinality: optional, one - Reviewer string - // including AnnotatorType: one of "Person", "Organization" or "Tool" - ReviewerType string - - // DEPRECATED in version 2.0 of spec - // 9.2: Review Date: YYYY-MM-DDThh:mm:ssZ - // Cardinality: conditional (mandatory, one) if there is a Reviewer - ReviewDate string - - // DEPRECATED in version 2.0 of spec - // 9.3: Review Comment - // Cardinality: optional, one - ReviewComment string -} diff --git a/spdx/snippet.go b/spdx/snippet.go deleted file mode 100644 index 6bffb8c8..00000000 --- a/spdx/snippet.go +++ /dev/null @@ -1,102 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - -package spdx - -type SnippetRangePointer struct { - // 5.3: Snippet Byte Range: [start byte]:[end byte] - // Cardinality: mandatory, one - Offset int `json:"offset,omitempty"` - - // 5.4: Snippet Line Range: [start line]:[end line] - // Cardinality: optional, one - LineNumber int `json:"lineNumber,omitempty"` - - FileSPDXIdentifier ElementID `json:"reference"` -} - -type SnippetRange struct { - StartPointer SnippetRangePointer `json:"startPointer"` - EndPointer SnippetRangePointer `json:"endPointer"` -} - -// Snippet2_1 is a Snippet section of an SPDX Document for version 2.1 of the spec. -type Snippet2_1 struct { - - // 5.1: Snippet SPDX Identifier: "SPDXRef-[idstring]" - // Cardinality: mandatory, one - SnippetSPDXIdentifier ElementID `json:"SPDXID"` - - // 5.2: Snippet from File SPDX Identifier - // Cardinality: mandatory, one - SnippetFromFileSPDXIdentifier ElementID `json:"snippetFromFile"` - - // Ranges denotes the start/end byte offsets or line numbers that the snippet is relevant to - Ranges []SnippetRange `json:"ranges"` - - // 5.5: Snippet Concluded License: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - SnippetLicenseConcluded string `json:"licenseConcluded"` - - // 5.6: License Information in Snippet: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: optional, one or many - LicenseInfoInSnippet []string `json:"licenseInfoInSnippets,omitempty"` - - // 5.7: Snippet Comments on License - // Cardinality: optional, one - SnippetLicenseComments string `json:"licenseComments,omitempty"` - - // 5.8: Snippet Copyright Text: copyright notice(s) text, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - SnippetCopyrightText string `json:"copyrightText"` - - // 5.9: Snippet Comment - // Cardinality: optional, one - SnippetComment string `json:"comment,omitempty"` - - // 5.10: Snippet Name - // Cardinality: optional, one - SnippetName string `json:"name,omitempty"` -} - -// Snippet2_2 is a Snippet section of an SPDX Document for version 2.2 of the spec. -type Snippet2_2 struct { - - // 5.1: Snippet SPDX Identifier: "SPDXRef-[idstring]" - // Cardinality: mandatory, one - SnippetSPDXIdentifier ElementID `json:"SPDXID"` - - // 5.2: Snippet from File SPDX Identifier - // Cardinality: mandatory, one - SnippetFromFileSPDXIdentifier ElementID `json:"snippetFromFile"` - - // Ranges denotes the start/end byte offsets or line numbers that the snippet is relevant to - Ranges []SnippetRange `json:"ranges"` - - // 5.5: Snippet Concluded License: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - SnippetLicenseConcluded string `json:"licenseConcluded"` - - // 5.6: License Information in Snippet: SPDX License Expression, "NONE" or "NOASSERTION" - // Cardinality: optional, one or many - LicenseInfoInSnippet []string `json:"licenseInfoInSnippets,omitempty"` - - // 5.7: Snippet Comments on License - // Cardinality: optional, one - SnippetLicenseComments string `json:"licenseComments,omitempty"` - - // 5.8: Snippet Copyright Text: copyright notice(s) text, "NONE" or "NOASSERTION" - // Cardinality: mandatory, one - SnippetCopyrightText string `json:"copyrightText"` - - // 5.9: Snippet Comment - // Cardinality: optional, one - SnippetComment string `json:"comment,omitempty"` - - // 5.10: Snippet Name - // Cardinality: optional, one - SnippetName string `json:"name,omitempty"` - - // 5.11: Snippet Attribution Text - // Cardinality: optional, one or many - SnippetAttributionTexts []string `json:"-"` -} diff --git a/spdx/v2_1/annotation.go b/spdx/v2_1/annotation.go new file mode 100644 index 00000000..45fcd13f --- /dev/null +++ b/spdx/v2_1/annotation.go @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_1 + +import "github.com/spdx/tools-golang/spdx/common" + +// Annotation is an Annotation section of an SPDX Document for version 2.1 of the spec. +type Annotation struct { + // 8.1: Annotator + // Cardinality: conditional (mandatory, one) if there is an Annotation + Annotator common.Annotator `json:"annotator"` + + // 8.2: Annotation Date: YYYY-MM-DDThh:mm:ssZ + // Cardinality: conditional (mandatory, one) if there is an Annotation + AnnotationDate string `json:"annotationDate"` + + // 8.3: Annotation Type: "REVIEW" or "OTHER" + // Cardinality: conditional (mandatory, one) if there is an Annotation + AnnotationType string `json:"annotationType"` + + // 8.4: SPDX Identifier Reference + // Cardinality: conditional (mandatory, one) if there is an Annotation + // This field is not used in hierarchical data formats where the referenced element is clear, such as JSON or YAML. + AnnotationSPDXIdentifier common.DocElementID `json:"-"` + + // 8.5: Annotation Comment + // Cardinality: conditional (mandatory, one) if there is an Annotation + AnnotationComment string `json:"comment"` +} diff --git a/spdx/v2_1/creation_info.go b/spdx/v2_1/creation_info.go new file mode 100644 index 00000000..f4c4f417 --- /dev/null +++ b/spdx/v2_1/creation_info.go @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_1 + +import "github.com/spdx/tools-golang/spdx/common" + +// CreationInfo is a Document Creation Information section of an +// SPDX Document for version 2.1 of the spec. +type CreationInfo struct { + // 2.7: License List Version + // Cardinality: optional, one + LicenseListVersion string `json:"licenseListVersion"` + + // 2.8: Creators: may have multiple keys for Person, Organization + // and/or Tool + // Cardinality: mandatory, one or many + Creators []common.Creator `json:"creators"` + + // 2.9: Created: data format YYYY-MM-DDThh:mm:ssZ + // Cardinality: mandatory, one + Created string `json:"created"` + + // 2.10: Creator Comment + // Cardinality: optional, one + CreatorComment string `json:"comment"` +} diff --git a/spdx/v2_1/document.go b/spdx/v2_1/document.go new file mode 100644 index 00000000..9721463c --- /dev/null +++ b/spdx/v2_1/document.go @@ -0,0 +1,65 @@ +// Package spdx contains the struct definition for an SPDX Document +// and its constituent parts. +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +package v2_1 + +import "github.com/spdx/tools-golang/spdx/common" + +// ExternalDocumentRef is a reference to an external SPDX document +// as defined in section 2.6 for version 2.1 of the spec. +type ExternalDocumentRef struct { + // DocumentRefID is the ID string defined in the start of the + // reference. It should _not_ contain the "DocumentRef-" part + // of the mandatory ID string. + DocumentRefID string `json:"externalDocumentId"` + + // URI is the URI defined for the external document + URI string `json:"spdxDocument"` + + // Checksum is the actual hash data + Checksum common.Checksum `json:"checksum"` +} + +// Document is an SPDX Document for version 2.1 of the spec. +// See https://spdx.org/sites/cpstandard/files/pages/files/spdxversion2.1.pdf +type Document struct { + // 2.1: SPDX Version; should be in the format "SPDX-2.1" + // Cardinality: mandatory, one + SPDXVersion string `json:"spdxVersion"` + + // 2.2: Data License; should be "CC0-1.0" + // Cardinality: mandatory, one + DataLicense string `json:"dataLicense"` + + // 2.3: SPDX Identifier; should be "DOCUMENT" to represent + // mandatory identifier of SPDXRef-DOCUMENT + // Cardinality: mandatory, one + SPDXIdentifier common.ElementID `json:"SPDXID"` + + // 2.4: Document Name + // Cardinality: mandatory, one + DocumentName string `json:"name"` + + // 2.5: Document Namespace + // Cardinality: mandatory, one + DocumentNamespace string `json:"documentNamespace"` + + // 2.6: External Document References + // Cardinality: optional, one or many + ExternalDocumentReferences []ExternalDocumentRef `json:"externalDocumentRefs,omitempty"` + + // 2.11: Document Comment + // Cardinality: optional, one + DocumentComment string `json:"comment,omitempty"` + + CreationInfo *CreationInfo `json:"creationInfo"` + Packages []*Package `json:"packages"` + Files []*File `json:"files"` + OtherLicenses []*OtherLicense `json:"hasExtractedLicensingInfos"` + Relationships []*Relationship `json:"relationships"` + Annotations []*Annotation `json:"annotations"` + Snippets []Snippet `json:"snippets"` + + // DEPRECATED in version 2.0 of spec + Reviews []*Review +} diff --git a/spdx/v2_1/file.go b/spdx/v2_1/file.go new file mode 100644 index 00000000..ffdec943 --- /dev/null +++ b/spdx/v2_1/file.go @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_1 + +import "github.com/spdx/tools-golang/spdx/common" + +// File is a File section of an SPDX Document for version 2.1 of the spec. +type File struct { + // 4.1: File Name + // Cardinality: mandatory, one + FileName string `json:"fileName"` + + // 4.2: File SPDX Identifier: "SPDXRef-[idstring]" + // Cardinality: mandatory, one + FileSPDXIdentifier common.ElementID `json:"SPDXID"` + + // 4.3: File Types + // Cardinality: optional, multiple + FileTypes []string `json:"fileTypes,omitempty"` + + // 4.4: File Checksum: may have keys for SHA1, SHA256 and/or MD5 + // Cardinality: mandatory, one SHA1, others may be optionally provided + Checksums []common.Checksum `json:"checksums"` + + // 4.5: Concluded License: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + LicenseConcluded string `json:"licenseConcluded"` + + // 4.6: License Information in File: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one or many + LicenseInfoInFiles []string `json:"licenseInfoInFiles"` + + // 4.7: Comments on License + // Cardinality: optional, one + LicenseComments string `json:"licenseComments,omitempty"` + + // 4.8: Copyright Text: copyright notice(s) text, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + FileCopyrightText string `json:"copyrightText"` + + // DEPRECATED in version 2.1 of spec + // 4.9-4.11: Artifact of Project variables (defined below) + // Cardinality: optional, one or many + ArtifactOfProjects []*ArtifactOfProject `json:"-"` + + // 4.12: File Comment + // Cardinality: optional, one + FileComment string `json:"comment,omitempty"` + + // 4.13: File Notice + // Cardinality: optional, one + FileNotice string `json:"noticeText,omitempty"` + + // 4.14: File Contributor + // Cardinality: optional, one or many + FileContributors []string `json:"fileContributors,omitempty"` + + // DEPRECATED in version 2.0 of spec + // 4.15: File Dependencies + // Cardinality: optional, one or many + FileDependencies []string `json:"-"` + + // Snippets contained in this File + // Note that Snippets could be defined in a different Document! However, + // the only ones that _THIS_ document can contain are the ones that are + // defined here -- so this should just be an ElementID. + Snippets map[common.ElementID]*Snippet `json:"-"` + + Annotations []Annotation `json:"annotations"` +} + +// ArtifactOfProject is a DEPRECATED collection of data regarding +// a Package, as defined in sections 4.9-4.11 in version 2.1 of the spec. +type ArtifactOfProject struct { + + // DEPRECATED in version 2.1 of spec + // 4.9: Artifact of Project Name + // Cardinality: conditional, required if present, one per AOP + Name string + + // DEPRECATED in version 2.1 of spec + // 4.10: Artifact of Project Homepage: URL or "UNKNOWN" + // Cardinality: optional, one per AOP + HomePage string + + // DEPRECATED in version 2.1 of spec + // 4.11: Artifact of Project Uniform Resource Identifier + // Cardinality: optional, one per AOP + URI string +} diff --git a/spdx/v2_1/other_license.go b/spdx/v2_1/other_license.go new file mode 100644 index 00000000..6ae09feb --- /dev/null +++ b/spdx/v2_1/other_license.go @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_1 + +// OtherLicense is an Other License Information section of an +// SPDX Document for version 2.1 of the spec. +type OtherLicense struct { + // 6.1: License Identifier: "LicenseRef-[idstring]" + // Cardinality: conditional (mandatory, one) if license is not + // on SPDX License List + LicenseIdentifier string `json:"licenseId"` + + // 6.2: Extracted Text + // Cardinality: conditional (mandatory, one) if there is a + // License Identifier assigned + ExtractedText string `json:"extractedText"` + + // 6.3: License Name: single line of text or "NOASSERTION" + // Cardinality: conditional (mandatory, one) if license is not + // on SPDX License List + LicenseName string `json:"name,omitempty"` + + // 6.4: License Cross Reference + // Cardinality: conditional (optional, one or many) if license + // is not on SPDX License List + LicenseCrossReferences []string `json:"seeAlsos,omitempty"` + + // 6.5: License Comment + // Cardinality: optional, one + LicenseComment string `json:"comment,omitempty"` +} diff --git a/spdx/v2_1/package.go b/spdx/v2_1/package.go new file mode 100644 index 00000000..4bf56366 --- /dev/null +++ b/spdx/v2_1/package.go @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_1 + +import "github.com/spdx/tools-golang/spdx/common" + +// Package is a Package section of an SPDX Document for version 2.1 of the spec. +type Package struct { + // 3.1: Package Name + // Cardinality: mandatory, one + PackageName string `json:"name"` + + // 3.2: Package SPDX Identifier: "SPDXRef-[idstring]" + // Cardinality: mandatory, one + PackageSPDXIdentifier common.ElementID `json:"SPDXID"` + + // 3.3: Package Version + // Cardinality: optional, one + PackageVersion string `json:"versionInfo,omitempty"` + + // 3.4: Package File Name + // Cardinality: optional, one + PackageFileName string `json:"packageFileName,omitempty"` + + // 3.5: Package Supplier: may have single result for either Person or Organization, + // or NOASSERTION + // Cardinality: optional, one + PackageSupplier *common.Supplier `json:"supplier,omitempty"` + + // 3.6: Package Originator: may have single result for either Person or Organization, + // or NOASSERTION + // Cardinality: optional, one + PackageOriginator *common.Originator `json:"originator,omitempty"` + + // 3.7: Package Download Location + // Cardinality: mandatory, one + PackageDownloadLocation string `json:"downloadLocation"` + + // 3.8: FilesAnalyzed + // Cardinality: optional, one; default value is "true" if omitted + FilesAnalyzed bool `json:"filesAnalyzed,omitempty"` + // NOT PART OF SPEC: did FilesAnalyzed tag appear? + IsFilesAnalyzedTagPresent bool `json:"-"` + + // 3.9: Package Verification Code + PackageVerificationCode common.PackageVerificationCode `json:"packageVerificationCode"` + + // 3.10: Package Checksum: may have keys for SHA1, SHA256 and/or MD5 + // Cardinality: optional, one or many + PackageChecksums []common.Checksum `json:"checksums,omitempty"` + + // 3.11: Package Home Page + // Cardinality: optional, one + PackageHomePage string `json:"homepage,omitempty"` + + // 3.12: Source Information + // Cardinality: optional, one + PackageSourceInfo string `json:"sourceInfo,omitempty"` + + // 3.13: Concluded License: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + PackageLicenseConcluded string `json:"licenseConcluded"` + + // 3.14: All Licenses Info from Files: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one or many if filesAnalyzed is true / omitted; + // zero (must be omitted) if filesAnalyzed is false + PackageLicenseInfoFromFiles []string `json:"licenseInfoFromFiles"` + + // 3.15: Declared License: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + PackageLicenseDeclared string `json:"licenseDeclared"` + + // 3.16: Comments on License + // Cardinality: optional, one + PackageLicenseComments string `json:"licenseComments,omitempty"` + + // 3.17: Copyright Text: copyright notice(s) text, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + PackageCopyrightText string `json:"copyrightText"` + + // 3.18: Package Summary Description + // Cardinality: optional, one + PackageSummary string `json:"summary,omitempty"` + + // 3.19: Package Detailed Description + // Cardinality: optional, one + PackageDescription string `json:"description,omitempty"` + + // 3.20: Package Comment + // Cardinality: optional, one + PackageComment string `json:"comment,omitempty"` + + // 3.21: Package External Reference + // Cardinality: optional, one or many + PackageExternalReferences []*PackageExternalReference `json:"externalRefs,omitempty"` + + // Files contained in this Package + Files []*File + + Annotations []Annotation `json:"annotations,omitempty"` +} + +// PackageExternalReference is an External Reference to additional info +// about a Package, as defined in section 3.21 in version 2.1 of the spec. +type PackageExternalReference struct { + // category is "SECURITY", "PACKAGE-MANAGER" or "OTHER" + Category string `json:"referenceCategory"` + + // type is an [idstring] as defined in Appendix VI; + // called RefType here due to "type" being a Golang keyword + RefType string `json:"referenceType"` + + // locator is a unique string to access the package-specific + // info, metadata or content within the target location + Locator string `json:"referenceLocator"` + + // 3.22: Package External Reference Comment + // Cardinality: conditional (optional, one) for each External Reference + ExternalRefComment string `json:"comment"` +} diff --git a/spdx/v2_1/relationship.go b/spdx/v2_1/relationship.go new file mode 100644 index 00000000..006e23fd --- /dev/null +++ b/spdx/v2_1/relationship.go @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_1 + +import "github.com/spdx/tools-golang/spdx/common" + +// Relationship is a Relationship section of an SPDX Document for +// version 2.1 of the spec. +type Relationship struct { + + // 7.1: Relationship + // Cardinality: optional, one or more; one per Relationship + // one mandatory for SPDX Document with multiple packages + // RefA and RefB are first and second item + // Relationship is type from 7.1.1 + RefA common.DocElementID `json:"spdxElementId"` + RefB common.DocElementID `json:"relatedSpdxElement"` + Relationship string `json:"relationshipType"` + + // 7.2: Relationship Comment + // Cardinality: optional, one + RelationshipComment string `json:"comment,omitempty"` +} diff --git a/spdx/v2_1/review.go b/spdx/v2_1/review.go new file mode 100644 index 00000000..8d70d00e --- /dev/null +++ b/spdx/v2_1/review.go @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_1 + +// Review is a Review section of an SPDX Document for version 2.1 of the spec. +// DEPRECATED in version 2.0 of spec; retained here for compatibility. +type Review struct { + + // DEPRECATED in version 2.0 of spec + // 9.1: Reviewer + // Cardinality: optional, one + Reviewer string + // including AnnotatorType: one of "Person", "Organization" or "Tool" + ReviewerType string + + // DEPRECATED in version 2.0 of spec + // 9.2: Review Date: YYYY-MM-DDThh:mm:ssZ + // Cardinality: conditional (mandatory, one) if there is a Reviewer + ReviewDate string + + // DEPRECATED in version 2.0 of spec + // 9.3: Review Comment + // Cardinality: optional, one + ReviewComment string +} diff --git a/spdx/v2_1/snippet.go b/spdx/v2_1/snippet.go new file mode 100644 index 00000000..e4d2f593 --- /dev/null +++ b/spdx/v2_1/snippet.go @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_1 + +import "github.com/spdx/tools-golang/spdx/common" + +// Snippet is a Snippet section of an SPDX Document for version 2.1 of the spec. +type Snippet struct { + + // 5.1: Snippet SPDX Identifier: "SPDXRef-[idstring]" + // Cardinality: mandatory, one + SnippetSPDXIdentifier common.ElementID `json:"SPDXID"` + + // 5.2: Snippet from File SPDX Identifier + // Cardinality: mandatory, one + SnippetFromFileSPDXIdentifier common.ElementID `json:"snippetFromFile"` + + // Ranges denotes the start/end byte offsets or line numbers that the snippet is relevant to + Ranges []common.SnippetRange `json:"ranges"` + + // 5.5: Snippet Concluded License: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + SnippetLicenseConcluded string `json:"licenseConcluded"` + + // 5.6: License Information in Snippet: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: optional, one or many + LicenseInfoInSnippet []string `json:"licenseInfoInSnippets,omitempty"` + + // 5.7: Snippet Comments on License + // Cardinality: optional, one + SnippetLicenseComments string `json:"licenseComments,omitempty"` + + // 5.8: Snippet Copyright Text: copyright notice(s) text, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + SnippetCopyrightText string `json:"copyrightText"` + + // 5.9: Snippet Comment + // Cardinality: optional, one + SnippetComment string `json:"comment,omitempty"` + + // 5.10: Snippet Name + // Cardinality: optional, one + SnippetName string `json:"name,omitempty"` +} diff --git a/spdx/v2_2/annotation.go b/spdx/v2_2/annotation.go new file mode 100644 index 00000000..f2d5bc80 --- /dev/null +++ b/spdx/v2_2/annotation.go @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_2 + +import "github.com/spdx/tools-golang/spdx/common" + +// Annotation is an Annotation section of an SPDX Document for version 2.2 of the spec. +type Annotation struct { + // 8.1: Annotator + // Cardinality: conditional (mandatory, one) if there is an Annotation + Annotator common.Annotator `json:"annotator"` + + // 8.2: Annotation Date: YYYY-MM-DDThh:mm:ssZ + // Cardinality: conditional (mandatory, one) if there is an Annotation + AnnotationDate string `json:"annotationDate"` + + // 8.3: Annotation Type: "REVIEW" or "OTHER" + // Cardinality: conditional (mandatory, one) if there is an Annotation + AnnotationType string `json:"annotationType"` + + // 8.4: SPDX Identifier Reference + // Cardinality: conditional (mandatory, one) if there is an Annotation + // This field is not used in hierarchical data formats where the referenced element is clear, such as JSON or YAML. + AnnotationSPDXIdentifier common.DocElementID `json:"-"` + + // 8.5: Annotation Comment + // Cardinality: conditional (mandatory, one) if there is an Annotation + AnnotationComment string `json:"comment"` +} diff --git a/spdx/v2_2/creation_info.go b/spdx/v2_2/creation_info.go new file mode 100644 index 00000000..b68dadec --- /dev/null +++ b/spdx/v2_2/creation_info.go @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_2 + +import "github.com/spdx/tools-golang/spdx/common" + +// CreationInfo is a Document Creation Information section of an +// SPDX Document for version 2.2 of the spec. +type CreationInfo struct { + // 2.7: License List Version + // Cardinality: optional, one + LicenseListVersion string `json:"licenseListVersion"` + + // 2.8: Creators: may have multiple keys for Person, Organization + // and/or Tool + // Cardinality: mandatory, one or many + Creators []common.Creator `json:"creators"` + + // 2.9: Created: data format YYYY-MM-DDThh:mm:ssZ + // Cardinality: mandatory, one + Created string `json:"created"` + + // 2.10: Creator Comment + // Cardinality: optional, one + CreatorComment string `json:"comment"` +} diff --git a/spdx/v2_2/document.go b/spdx/v2_2/document.go new file mode 100644 index 00000000..d2391943 --- /dev/null +++ b/spdx/v2_2/document.go @@ -0,0 +1,65 @@ +// Package spdx contains the struct definition for an SPDX Document +// and its constituent parts. +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +package v2_2 + +import "github.com/spdx/tools-golang/spdx/common" + +// ExternalDocumentRef is a reference to an external SPDX document +// as defined in section 2.6 for version 2.2 of the spec. +type ExternalDocumentRef struct { + // DocumentRefID is the ID string defined in the start of the + // reference. It should _not_ contain the "DocumentRef-" part + // of the mandatory ID string. + DocumentRefID string `json:"externalDocumentId"` + + // URI is the URI defined for the external document + URI string `json:"spdxDocument"` + + // Checksum is the actual hash data + Checksum common.Checksum `json:"checksum"` +} + +// Document is an SPDX Document for version 2.2 of the spec. +// See https://spdx.github.io/spdx-spec/v2-draft/ (DRAFT) +type Document struct { + // 2.1: SPDX Version; should be in the format "SPDX-2.2" + // Cardinality: mandatory, one + SPDXVersion string `json:"spdxVersion"` + + // 2.2: Data License; should be "CC0-1.0" + // Cardinality: mandatory, one + DataLicense string `json:"dataLicense"` + + // 2.3: SPDX Identifier; should be "DOCUMENT" to represent + // mandatory identifier of SPDXRef-DOCUMENT + // Cardinality: mandatory, one + SPDXIdentifier common.ElementID `json:"SPDXID"` + + // 2.4: Document Name + // Cardinality: mandatory, one + DocumentName string `json:"name"` + + // 2.5: Document Namespace + // Cardinality: mandatory, one + DocumentNamespace string `json:"documentNamespace"` + + // 2.6: External Document References + // Cardinality: optional, one or many + ExternalDocumentReferences []ExternalDocumentRef `json:"externalDocumentRefs,omitempty"` + + // 2.11: Document Comment + // Cardinality: optional, one + DocumentComment string `json:"comment,omitempty"` + + CreationInfo *CreationInfo `json:"creationInfo"` + Packages []*Package `json:"packages"` + Files []*File `json:"files"` + OtherLicenses []*OtherLicense `json:"hasExtractedLicensingInfos"` + Relationships []*Relationship `json:"relationships"` + Annotations []*Annotation `json:"annotations"` + Snippets []Snippet `json:"snippets"` + + // DEPRECATED in version 2.0 of spec + Reviews []*Review +} diff --git a/spdx/v2_2/file.go b/spdx/v2_2/file.go new file mode 100644 index 00000000..43c2608c --- /dev/null +++ b/spdx/v2_2/file.go @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_2 + +import "github.com/spdx/tools-golang/spdx/common" + +// File is a File section of an SPDX Document for version 2.2 of the spec. +type File struct { + // 4.1: File Name + // Cardinality: mandatory, one + FileName string `json:"fileName"` + + // 4.2: File SPDX Identifier: "SPDXRef-[idstring]" + // Cardinality: mandatory, one + FileSPDXIdentifier common.ElementID `json:"SPDXID"` + + // 4.3: File Types + // Cardinality: optional, multiple + FileTypes []string `json:"fileTypes,omitempty"` + + // 4.4: File Checksum: may have keys for SHA1, SHA256 and/or MD5 + // Cardinality: mandatory, one SHA1, others may be optionally provided + Checksums []common.Checksum `json:"checksums"` + + // 4.5: Concluded License: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + LicenseConcluded string `json:"licenseConcluded"` + + // 4.6: License Information in File: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one or many + LicenseInfoInFiles []string `json:"licenseInfoInFiles"` + + // 4.7: Comments on License + // Cardinality: optional, one + LicenseComments string `json:"licenseComments,omitempty"` + + // 4.8: Copyright Text: copyright notice(s) text, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + FileCopyrightText string `json:"copyrightText"` + + // DEPRECATED in version 2.1 of spec + // 4.9-4.11: Artifact of Project variables (defined below) + // Cardinality: optional, one or many + ArtifactOfProjects []*ArtifactOfProject `json:"-"` + + // 4.12: File Comment + // Cardinality: optional, one + FileComment string `json:"comment,omitempty"` + + // 4.13: File Notice + // Cardinality: optional, one + FileNotice string `json:"noticeText,omitempty"` + + // 4.14: File Contributor + // Cardinality: optional, one or many + FileContributors []string `json:"fileContributors,omitempty"` + + // 4.15: File Attribution Text + // Cardinality: optional, one or many + FileAttributionTexts []string `json:"attributionTexts,omitempty"` + + // DEPRECATED in version 2.0 of spec + // 4.16: File Dependencies + // Cardinality: optional, one or many + FileDependencies []string `json:"-"` + + // Snippets contained in this File + // Note that Snippets could be defined in a different Document! However, + // the only ones that _THIS_ document can contain are this ones that are + // defined here -- so this should just be an ElementID. + Snippets map[common.ElementID]*Snippet `json:"-"` + + Annotations []Annotation `json:"annotations,omitempty"` +} + +// ArtifactOfProject is a DEPRECATED collection of data regarding +// a Package, as defined in sections 4.9-4.11 in version 2.2 of the spec. +type ArtifactOfProject struct { + + // DEPRECATED in version 2.1 of spec + // 4.9: Artifact of Project Name + // Cardinality: conditional, required if present, one per AOP + Name string + + // DEPRECATED in version 2.1 of spec + // 4.10: Artifact of Project Homepage: URL or "UNKNOWN" + // Cardinality: optional, one per AOP + HomePage string + + // DEPRECATED in version 2.1 of spec + // 4.11: Artifact of Project Uniform Resource Identifier + // Cardinality: optional, one per AOP + URI string +} diff --git a/spdx/v2_2/other_license.go b/spdx/v2_2/other_license.go new file mode 100644 index 00000000..1580169f --- /dev/null +++ b/spdx/v2_2/other_license.go @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_2 + +// OtherLicense is an Other License Information section of an +// SPDX Document for version 2.2 of the spec. +type OtherLicense struct { + // 6.1: License Identifier: "LicenseRef-[idstring]" + // Cardinality: conditional (mandatory, one) if license is not + // on SPDX License List + LicenseIdentifier string `json:"licenseId"` + + // 6.2: Extracted Text + // Cardinality: conditional (mandatory, one) if there is a + // License Identifier assigned + ExtractedText string `json:"extractedText"` + + // 6.3: License Name: single line of text or "NOASSERTION" + // Cardinality: conditional (mandatory, one) if license is not + // on SPDX License List + LicenseName string `json:"name,omitempty"` + + // 6.4: License Cross Reference + // Cardinality: conditional (optional, one or many) if license + // is not on SPDX License List + LicenseCrossReferences []string `json:"seeAlsos,omitempty"` + + // 6.5: License Comment + // Cardinality: optional, one + LicenseComment string `json:"comment,omitempty"` +} diff --git a/spdx/v2_2/package.go b/spdx/v2_2/package.go new file mode 100644 index 00000000..f8eff78e --- /dev/null +++ b/spdx/v2_2/package.go @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_2 + +import "github.com/spdx/tools-golang/spdx/common" + +// Package is a Package section of an SPDX Document for version 2.2 of the spec. +type Package struct { + // NOT PART OF SPEC + // flag: does this "package" contain files that were in fact "unpackaged", + // e.g. included directly in the Document without being in a Package? + IsUnpackaged bool + + // 3.1: Package Name + // Cardinality: mandatory, one + PackageName string `json:"name"` + + // 3.2: Package SPDX Identifier: "SPDXRef-[idstring]" + // Cardinality: mandatory, one + PackageSPDXIdentifier common.ElementID `json:"SPDXID"` + + // 3.3: Package Version + // Cardinality: optional, one + PackageVersion string `json:"versionInfo,omitempty"` + + // 3.4: Package File Name + // Cardinality: optional, one + PackageFileName string `json:"packageFileName,omitempty"` + + // 3.5: Package Supplier: may have single result for either Person or Organization, + // or NOASSERTION + // Cardinality: optional, one + PackageSupplier *common.Supplier `json:"supplier,omitempty"` + + // 3.6: Package Originator: may have single result for either Person or Organization, + // or NOASSERTION + // Cardinality: optional, one + PackageOriginator *common.Originator `json:"originator,omitempty"` + + // 3.7: Package Download Location + // Cardinality: mandatory, one + PackageDownloadLocation string `json:"downloadLocation"` + + // 3.8: FilesAnalyzed + // Cardinality: optional, one; default value is "true" if omitted + FilesAnalyzed bool `json:"filesAnalyzed,omitempty"` + // NOT PART OF SPEC: did FilesAnalyzed tag appear? + IsFilesAnalyzedTagPresent bool + + // 3.9: Package Verification Code + PackageVerificationCode common.PackageVerificationCode `json:"packageVerificationCode"` + + // 3.10: Package Checksum: may have keys for SHA1, SHA256 and/or MD5 + // Cardinality: optional, one or many + PackageChecksums []common.Checksum `json:"checksums"` + + // 3.11: Package Home Page + // Cardinality: optional, one + PackageHomePage string `json:"homepage,omitempty"` + + // 3.12: Source Information + // Cardinality: optional, one + PackageSourceInfo string `json:"sourceInfo,omitempty"` + + // 3.13: Concluded License: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + PackageLicenseConcluded string `json:"licenseConcluded"` + + // 3.14: All Licenses Info from Files: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one or many if filesAnalyzed is true / omitted; + // zero (must be omitted) if filesAnalyzed is false + PackageLicenseInfoFromFiles []string `json:"licenseInfoFromFiles"` + + // 3.15: Declared License: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + PackageLicenseDeclared string `json:"licenseDeclared"` + + // 3.16: Comments on License + // Cardinality: optional, one + PackageLicenseComments string `json:"licenseComments,omitempty"` + + // 3.17: Copyright Text: copyright notice(s) text, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + PackageCopyrightText string `json:"copyrightText"` + + // 3.18: Package Summary Description + // Cardinality: optional, one + PackageSummary string `json:"summary,omitempty"` + + // 3.19: Package Detailed Description + // Cardinality: optional, one + PackageDescription string `json:"description,omitempty"` + + // 3.20: Package Comment + // Cardinality: optional, one + PackageComment string `json:"comment,omitempty"` + + // 3.21: Package External Reference + // Cardinality: optional, one or many + PackageExternalReferences []*PackageExternalReference `json:"externalRefs,omitempty"` + + // 3.22: Package External Reference Comment + // Cardinality: conditional (optional, one) for each External Reference + // contained within PackageExternalReference2_1 struct, if present + + // 3.23: Package Attribution Text + // Cardinality: optional, one or many + PackageAttributionTexts []string `json:"attributionTexts,omitempty"` + + // Files contained in this Package + Files []*File + + Annotations []Annotation `json:"annotations"` +} + +// PackageExternalReference is an External Reference to additional info +// about a Package, as defined in section 3.21 in version 2.2 of the spec. +type PackageExternalReference struct { + // category is "SECURITY", "PACKAGE-MANAGER" or "OTHER" + Category string `json:"referenceCategory"` + + // type is an [idstring] as defined in Appendix VI; + // called RefType here due to "type" being a Golang keyword + RefType string `json:"referenceType"` + + // locator is a unique string to access the package-specific + // info, metadata or content within the target location + Locator string `json:"referenceLocator"` + + // 3.22: Package External Reference Comment + // Cardinality: conditional (optional, one) for each External Reference + ExternalRefComment string `json:"comment"` +} diff --git a/spdx/v2_2/relationship.go b/spdx/v2_2/relationship.go new file mode 100644 index 00000000..6b448989 --- /dev/null +++ b/spdx/v2_2/relationship.go @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_2 + +import "github.com/spdx/tools-golang/spdx/common" + +// Relationship is a Relationship section of an SPDX Document for +// version 2.2 of the spec. +type Relationship struct { + + // 7.1: Relationship + // Cardinality: optional, one or more; one per Relationship + // one mandatory for SPDX Document with multiple packages + // RefA and RefB are first and second item + // Relationship is type from 7.1.1 + RefA common.DocElementID `json:"spdxElementId"` + RefB common.DocElementID `json:"relatedSpdxElement"` + Relationship string `json:"relationshipType"` + + // 7.2: Relationship Comment + // Cardinality: optional, one + RelationshipComment string `json:"comment,omitempty"` +} diff --git a/spdx/v2_2/review.go b/spdx/v2_2/review.go new file mode 100644 index 00000000..4cc7c422 --- /dev/null +++ b/spdx/v2_2/review.go @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_2 + +// Review is a Review section of an SPDX Document for version 2.2 of the spec. +// DEPRECATED in version 2.0 of spec; retained here for compatibility. +type Review struct { + + // DEPRECATED in version 2.0 of spec + // 9.1: Reviewer + // Cardinality: optional, one + Reviewer string + // including AnnotatorType: one of "Person", "Organization" or "Tool" + ReviewerType string + + // DEPRECATED in version 2.0 of spec + // 9.2: Review Date: YYYY-MM-DDThh:mm:ssZ + // Cardinality: conditional (mandatory, one) if there is a Reviewer + ReviewDate string + + // DEPRECATED in version 2.0 of spec + // 9.3: Review Comment + // Cardinality: optional, one + ReviewComment string +} diff --git a/spdx/v2_2/snippet.go b/spdx/v2_2/snippet.go new file mode 100644 index 00000000..913007a4 --- /dev/null +++ b/spdx/v2_2/snippet.go @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package v2_2 + +import "github.com/spdx/tools-golang/spdx/common" + +// Snippet is a Snippet section of an SPDX Document for version 2.2 of the spec. +type Snippet struct { + + // 5.1: Snippet SPDX Identifier: "SPDXRef-[idstring]" + // Cardinality: mandatory, one + SnippetSPDXIdentifier common.ElementID `json:"SPDXID"` + + // 5.2: Snippet from File SPDX Identifier + // Cardinality: mandatory, one + SnippetFromFileSPDXIdentifier common.ElementID `json:"snippetFromFile"` + + // Ranges denotes the start/end byte offsets or line numbers that the snippet is relevant to + Ranges []common.SnippetRange `json:"ranges"` + + // 5.5: Snippet Concluded License: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + SnippetLicenseConcluded string `json:"licenseConcluded"` + + // 5.6: License Information in Snippet: SPDX License Expression, "NONE" or "NOASSERTION" + // Cardinality: optional, one or many + LicenseInfoInSnippet []string `json:"licenseInfoInSnippets,omitempty"` + + // 5.7: Snippet Comments on License + // Cardinality: optional, one + SnippetLicenseComments string `json:"licenseComments,omitempty"` + + // 5.8: Snippet Copyright Text: copyright notice(s) text, "NONE" or "NOASSERTION" + // Cardinality: mandatory, one + SnippetCopyrightText string `json:"copyrightText"` + + // 5.9: Snippet Comment + // Cardinality: optional, one + SnippetComment string `json:"comment,omitempty"` + + // 5.10: Snippet Name + // Cardinality: optional, one + SnippetName string `json:"name,omitempty"` + + // 5.11: Snippet Attribution Text + // Cardinality: optional, one or many + SnippetAttributionTexts []string `json:"-"` +} From 9ae1bd2f8e0dabb0845f1225b54f23e8f3a429f1 Mon Sep 17 00:00:00 2001 From: Brandon Lum Date: Tue, 19 Jul 2022 16:43:48 -0400 Subject: [PATCH 2/2] replace all v2_1, v2_2 with new convention Signed-off-by: Brandon Lum --- builder/build.go | 25 +- builder/build_test.go | 102 +++--- builder/builder2v1/build_creation_info.go | 9 +- builder/builder2v1/build_file.go | 17 +- builder/builder2v1/build_file_test.go | 10 +- builder/builder2v1/build_package.go | 14 +- builder/builder2v1/build_package_test.go | 14 +- builder/builder2v1/build_relationship.go | 11 +- builder/builder2v1/build_relationship_test.go | 6 +- builder/builder2v2/build_creation_info.go | 9 +- builder/builder2v2/build_file.go | 17 +- builder/builder2v2/build_file_test.go | 10 +- builder/builder2v2/build_package.go | 14 +- builder/builder2v2/build_package_test.go | 14 +- builder/builder2v2/build_relationship.go | 11 +- builder/builder2v2/build_relationship_test.go | 6 +- docs/jsonloader.md | 4 +- docs/jsonsaver.md | 2 +- examples/10-jsonloader/example_json_loader.go | 2 +- examples/11-yamltotv/exampleyamltotv.go | 5 +- examples/12-tvtoyaml/exampletvtoyaml.go | 2 +- examples/13-yamlloader/exampleYAMLLoader.go | 2 +- examples/6-licensediff/example_licensediff.go | 6 +- examples/7-rdfloader/exampleRDFLoader.go | 3 +- examples/8-jsontotv/examplejsontotv.go | 2 +- examples/9-tvtojson/exampletvtojson.go | 2 +- idsearcher/idsearcher.go | 7 +- json/json_test.go | 112 ++++--- json/parser.go | 6 +- json/writer.go | 4 +- licensediff/licensediff.go | 7 +- licensediff/licensediff_test.go | 316 +++++++++--------- rdfloader/parser2v2/license_utils.go | 9 +- rdfloader/parser2v2/parse_annotation.go | 13 +- rdfloader/parser2v2/parse_annotation_test.go | 15 +- rdfloader/parser2v2/parse_creation_info.go | 10 +- .../parser2v2/parse_creation_info_test.go | 15 +- rdfloader/parser2v2/parse_file.go | 25 +- rdfloader/parser2v2/parse_file_test.go | 45 +-- rdfloader/parser2v2/parse_license.go | 5 +- rdfloader/parser2v2/parse_license_test.go | 3 +- .../parser2v2/parse_other_license_info.go | 5 +- .../parse_other_license_info_test.go | 3 +- rdfloader/parser2v2/parse_package.go | 39 +-- rdfloader/parser2v2/parse_package_test.go | 95 +++--- rdfloader/parser2v2/parse_relationship.go | 22 +- .../parser2v2/parse_relationship_test.go | 34 +- rdfloader/parser2v2/parse_review.go | 5 +- rdfloader/parser2v2/parse_snippet_info.go | 28 +- .../parser2v2/parse_snippet_info_test.go | 52 +-- rdfloader/parser2v2/parse_spdx_document.go | 14 +- .../parser2v2/parse_spdx_document_test.go | 3 +- rdfloader/parser2v2/parser.go | 28 +- rdfloader/parser2v2/types.go | 17 +- rdfloader/parser2v2/utils.go | 31 +- rdfloader/parser2v2/utils_test.go | 9 +- rdfloader/rdfloader.go | 7 +- reporter/reporter.go | 11 +- reporter/reporter_test.go | 27 +- spdxlib/described_elements.go | 21 +- spdxlib/described_elements_test.go | 196 +++++------ spdxlib/documents.go | 17 +- spdxlib/documents_test.go | 100 +++--- spdxlib/element_ids.go | 5 +- spdxlib/element_ids_test.go | 7 +- spdxlib/relationships.go | 14 +- spdxlib/relationships_test.go | 72 ++-- tvloader/parser2v1/parse_annotation_test.go | 16 +- tvloader/parser2v1/parse_creation_info.go | 13 +- .../parser2v1/parse_creation_info_test.go | 30 +- tvloader/parser2v1/parse_file.go | 25 +- tvloader/parser2v1/parse_file_test.go | 113 +++---- tvloader/parser2v1/parse_other_license.go | 8 +- .../parser2v1/parse_other_license_test.go | 52 +-- tvloader/parser2v1/parse_package.go | 33 +- tvloader/parser2v1/parse_package_test.go | 131 ++++---- tvloader/parser2v1/parse_relationship_test.go | 22 +- tvloader/parser2v1/parse_review.go | 8 +- tvloader/parser2v1/parse_review_test.go | 100 +++--- tvloader/parser2v1/parse_snippet.go | 19 +- tvloader/parser2v1/parse_snippet_test.go | 117 +++---- tvloader/parser2v1/parser.go | 13 +- tvloader/parser2v1/types.go | 25 +- tvloader/parser2v1/util.go | 28 +- tvloader/parser2v1/util_test.go | 6 +- tvloader/parser2v2/parse_annotation_test.go | 16 +- tvloader/parser2v2/parse_creation_info.go | 13 +- .../parser2v2/parse_creation_info_test.go | 30 +- tvloader/parser2v2/parse_file.go | 25 +- tvloader/parser2v2/parse_file_test.go | 113 +++---- tvloader/parser2v2/parse_other_license.go | 8 +- .../parser2v2/parse_other_license_test.go | 52 +-- tvloader/parser2v2/parse_package.go | 33 +- tvloader/parser2v2/parse_package_test.go | 131 ++++---- tvloader/parser2v2/parse_relationship_test.go | 24 +- tvloader/parser2v2/parse_review.go | 8 +- tvloader/parser2v2/parse_review_test.go | 100 +++--- tvloader/parser2v2/parse_snippet.go | 19 +- tvloader/parser2v2/parse_snippet_test.go | 117 +++---- tvloader/parser2v2/parser.go | 11 +- tvloader/parser2v2/types.go | 25 +- tvloader/parser2v2/util.go | 32 +- tvloader/parser2v2/util_test.go | 8 +- tvloader/tvloader.go | 7 +- tvsaver/saver2v1/save_annotation.go | 7 +- tvsaver/saver2v1/save_annotation_test.go | 21 +- tvsaver/saver2v1/save_creation_info.go | 5 +- tvsaver/saver2v1/save_creation_info_test.go | 15 +- tvsaver/saver2v1/save_document.go | 7 +- tvsaver/saver2v1/save_document_test.go | 113 +++---- tvsaver/saver2v1/save_file.go | 9 +- tvsaver/saver2v1/save_file_test.go | 79 ++--- tvsaver/saver2v1/save_other_license.go | 4 +- tvsaver/saver2v1/save_other_license_test.go | 6 +- tvsaver/saver2v1/save_package.go | 7 +- tvsaver/saver2v1/save_package_test.go | 95 +++--- tvsaver/saver2v1/save_relationship.go | 9 +- tvsaver/saver2v1/save_relationship_test.go | 21 +- tvsaver/saver2v1/save_review.go | 4 +- tvsaver/saver2v1/save_review_test.go | 8 +- tvsaver/saver2v1/save_snippet.go | 9 +- tvsaver/saver2v1/save_snippet_test.go | 43 +-- tvsaver/saver2v2/save_annotation.go | 7 +- tvsaver/saver2v2/save_annotation_test.go | 21 +- tvsaver/saver2v2/save_creation_info.go | 5 +- tvsaver/saver2v2/save_creation_info_test.go | 15 +- tvsaver/saver2v2/save_document.go | 7 +- tvsaver/saver2v2/save_document_test.go | 113 +++---- tvsaver/saver2v2/save_file.go | 9 +- tvsaver/saver2v2/save_file_test.go | 79 ++--- tvsaver/saver2v2/save_other_license.go | 4 +- tvsaver/saver2v2/save_other_license_test.go | 6 +- tvsaver/saver2v2/save_package.go | 7 +- tvsaver/saver2v2/save_package_test.go | 97 +++--- tvsaver/saver2v2/save_relationship.go | 9 +- tvsaver/saver2v2/save_relationship_test.go | 33 +- tvsaver/saver2v2/save_review.go | 4 +- tvsaver/saver2v2/save_review_test.go | 8 +- tvsaver/saver2v2/save_snippet.go | 9 +- tvsaver/saver2v2/save_snippet_test.go | 43 +-- tvsaver/tvsaver.go | 7 +- utils/verification.go | 20 +- utils/verification_test.go | 96 +++--- yaml/parser.go | 8 +- yaml/writer.go | 6 +- yaml/yaml_test.go | 112 ++++--- 146 files changed, 2309 insertions(+), 2182 deletions(-) diff --git a/builder/build.go b/builder/build.go index 235e91d0..1594a04e 100644 --- a/builder/build.go +++ b/builder/build.go @@ -6,9 +6,12 @@ package builder import ( "fmt" + "github.com/spdx/tools-golang/builder/builder2v1" "github.com/spdx/tools-golang/builder/builder2v2" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== 2.1 builder ===== @@ -48,7 +51,7 @@ type Config2_1 struct { // - packageName: name of package / directory // - dirRoot: path to directory to be analyzed // - config: Config object -func Build2_1(packageName string, dirRoot string, config *Config2_1) (*spdx.Document2_1, error) { +func Build2_1(packageName string, dirRoot string, config *Config2_1) (*v2_1.Document, error) { // build Package section first -- will include Files and make the // package verification code available pkg, err := builder2v1.BuildPackageSection2_1(packageName, dirRoot, config.PathsIgnored) @@ -66,15 +69,15 @@ func Build2_1(packageName string, dirRoot string, config *Config2_1) (*spdx.Docu return nil, err } - doc := &spdx.Document2_1{ + doc := &v2_1.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), + SPDXIdentifier: common.ElementID("DOCUMENT"), DocumentName: packageName, DocumentNamespace: fmt.Sprintf("%s%s-%s", config.NamespacePrefix, packageName, pkg.PackageVerificationCode), CreationInfo: ci, - Packages: []*spdx.Package2_1{pkg}, - Relationships: []*spdx.Relationship2_1{rln}, + Packages: []*v2_1.Package{pkg}, + Relationships: []*v2_1.Relationship{rln}, } return doc, nil @@ -117,7 +120,7 @@ type Config2_2 struct { // - packageName: name of package / directory // - dirRoot: path to directory to be analyzed // - config: Config object -func Build2_2(packageName string, dirRoot string, config *Config2_2) (*spdx.Document2_2, error) { +func Build2_2(packageName string, dirRoot string, config *Config2_2) (*v2_2.Document, error) { // build Package section first -- will include Files and make the // package verification code available pkg, err := builder2v2.BuildPackageSection2_2(packageName, dirRoot, config.PathsIgnored) @@ -135,15 +138,15 @@ func Build2_2(packageName string, dirRoot string, config *Config2_2) (*spdx.Docu return nil, err } - doc := &spdx.Document2_2{ + doc := &v2_2.Document{ SPDXVersion: "SPDX-2.2", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), + SPDXIdentifier: common.ElementID("DOCUMENT"), DocumentName: packageName, DocumentNamespace: fmt.Sprintf("%s%s-%s", config.NamespacePrefix, packageName, pkg.PackageVerificationCode), CreationInfo: ci, - Packages: []*spdx.Package2_2{pkg}, - Relationships: []*spdx.Relationship2_2{rln}, + Packages: []*v2_2.Package{pkg}, + Relationships: []*v2_2.Relationship{rln}, } return doc, nil diff --git a/builder/build_test.go b/builder/build_test.go index be4fd42b..ff881de9 100644 --- a/builder/build_test.go +++ b/builder/build_test.go @@ -6,7 +6,7 @@ import ( "fmt" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" ) // ===== 2.1 Builder top-level Document test ===== @@ -21,7 +21,7 @@ func TestBuild2_1CreatesDocument(t *testing.T) { } config.TestValues["Created"] = "2018-10-19T04:38:00Z" - wantVerificationCode := spdx.PackageVerificationCode{Value: "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"} + wantVerificationCode := common.PackageVerificationCode{Value: "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"} doc, err := Build2_1("project1", dirRoot, config) if err != nil { @@ -41,7 +41,7 @@ func TestBuild2_1CreatesDocument(t *testing.T) { if doc.DataLicense != "CC0-1.0" { t.Errorf("expected %s, got %s", "CC0-1.0", doc.DataLicense) } - if doc.SPDXIdentifier != spdx.ElementID("DOCUMENT") { + if doc.SPDXIdentifier != common.ElementID("DOCUMENT") { t.Errorf("expected %s, got %v", "DOCUMENT", doc.SPDXIdentifier) } if doc.DocumentName != "project1" { @@ -78,7 +78,7 @@ func TestBuild2_1CreatesDocument(t *testing.T) { if pkg.PackageName != "project1" { t.Errorf("expected %v, got %v", "project1", pkg.PackageName) } - if pkg.PackageSPDXIdentifier != spdx.ElementID("Package-project1") { + if pkg.PackageSPDXIdentifier != common.ElementID("Package-project1") { t.Errorf("expected %v, got %v", "Package-project1", pkg.PackageSPDXIdentifier) } if pkg.PackageDownloadLocation != "NOASSERTION" { @@ -123,21 +123,21 @@ func TestBuild2_1CreatesDocument(t *testing.T) { if fileEmpty.FileName != "./emptyfile.testdata.txt" { t.Errorf("expected %v, got %v", "./emptyfile.testdata.txt", fileEmpty.FileName) } - if fileEmpty.FileSPDXIdentifier != spdx.ElementID("File0") { + if fileEmpty.FileSPDXIdentifier != common.ElementID("File0") { t.Errorf("expected %v, got %v", "File0", fileEmpty.FileSPDXIdentifier) } for _, checksum := range fileEmpty.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "da39a3ee5e6b4b0d3255bfef95601890afd80709" { t.Errorf("expected %v, got %v", "da39a3ee5e6b4b0d3255bfef95601890afd80709", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" { t.Errorf("expected %v, got %v", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "d41d8cd98f00b204e9800998ecf8427e" { t.Errorf("expected %v, got %v", "d41d8cd98f00b204e9800998ecf8427e", checksum.Value) } @@ -166,21 +166,21 @@ func TestBuild2_1CreatesDocument(t *testing.T) { if file1.FileName != "./file1.testdata.txt" { t.Errorf("expected %v, got %v", "./file1.testdata.txt", file1.FileName) } - if file1.FileSPDXIdentifier != spdx.ElementID("File1") { + if file1.FileSPDXIdentifier != common.ElementID("File1") { t.Errorf("expected %v, got %v", "File1", file1.FileSPDXIdentifier) } for _, checksum := range file1.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "024f870eb6323f532515f7a09d5646a97083b819" { t.Errorf("expected %v, got %v", "024f870eb6323f532515f7a09d5646a97083b819", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf" { t.Errorf("expected %v, got %v", "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "37c8208479dfe42d2bb29debd6e32d4a" { t.Errorf("expected %v, got %v", "37c8208479dfe42d2bb29debd6e32d4a", checksum.Value) } @@ -208,21 +208,21 @@ func TestBuild2_1CreatesDocument(t *testing.T) { if file3.FileName != "./file3.testdata.txt" { t.Errorf("expected %v, got %v", "./file3.testdata.txt", file3.FileName) } - if file3.FileSPDXIdentifier != spdx.ElementID("File2") { + if file3.FileSPDXIdentifier != common.ElementID("File2") { t.Errorf("expected %v, got %v", "File2", file3.FileSPDXIdentifier) } for _, checksum := range file3.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "a46114b70e163614f01c64adf44cdd438f158fce" { t.Errorf("expected %v, got %v", "a46114b70e163614f01c64adf44cdd438f158fce", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "9fc181b9892720a15df1a1e561860318db40621bd4040ccdf18e110eb01d04b4" { t.Errorf("expected %v, got %v", "9fc181b9892720a15df1a1e561860318db40621bd4040ccdf18e110eb01d04b4", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "3e02d3ab9c58eec6911dbba37570934f" { t.Errorf("expected %v, got %v", "3e02d3ab9c58eec6911dbba37570934f", checksum.Value) } @@ -250,21 +250,21 @@ func TestBuild2_1CreatesDocument(t *testing.T) { if file4.FileName != "./folder1/file4.testdata.txt" { t.Errorf("expected %v, got %v", "./folder1/file4.testdata.txt", file4.FileName) } - if file4.FileSPDXIdentifier != spdx.ElementID("File3") { + if file4.FileSPDXIdentifier != common.ElementID("File3") { t.Errorf("expected %v, got %v", "File3", file4.FileSPDXIdentifier) } for _, checksum := range file4.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "e623d7d7d782a7c8323c4d436acee4afab34320f" { t.Errorf("expected %v, got %v", "e623d7d7d782a7c8323c4d436acee4afab34320f", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "574fa42c5e0806c0f8906a44884166540206f021527729407cd5326838629c59" { t.Errorf("expected %v, got %v", "574fa42c5e0806c0f8906a44884166540206f021527729407cd5326838629c59", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "96e6a25d35df5b1c477710ef4d0c7210" { t.Errorf("expected %v, got %v", "96e6a25d35df5b1c477710ef4d0c7210", checksum.Value) } @@ -292,21 +292,21 @@ func TestBuild2_1CreatesDocument(t *testing.T) { if lastfile.FileName != "./lastfile.testdata.txt" { t.Errorf("expected %v, got %v", "./lastfile.testdata.txt", lastfile.FileName) } - if lastfile.FileSPDXIdentifier != spdx.ElementID("File4") { + if lastfile.FileSPDXIdentifier != common.ElementID("File4") { t.Errorf("expected %v, got %v", "File4", lastfile.FileSPDXIdentifier) } for _, checksum := range lastfile.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "26d6221d682d9ba59116f9753a701f34271c8ce1" { t.Errorf("expected %v, got %v", "26d6221d682d9ba59116f9753a701f34271c8ce1", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "0a4bdaf990e9b330ff72022dd78110ae98b60e08337cf2105b89856373416805" { t.Errorf("expected %v, got %v", "0a4bdaf990e9b330ff72022dd78110ae98b60e08337cf2105b89856373416805", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "f60baa793870d9085461ad6bbab50b7f" { t.Errorf("expected %v, got %v", "f60baa793870d9085461ad6bbab50b7f", checksum.Value) } @@ -337,10 +337,10 @@ func TestBuild2_1CreatesDocument(t *testing.T) { if rln == nil { t.Fatalf("expected non-nil Relationship, got nil") } - if rln.RefA != spdx.MakeDocElementID("", "DOCUMENT") { + if rln.RefA != common.MakeDocElementID("", "DOCUMENT") { t.Errorf("expected %v, got %v", "DOCUMENT", rln.RefA) } - if rln.RefB != spdx.MakeDocElementID("", "Package-project1") { + if rln.RefB != common.MakeDocElementID("", "Package-project1") { t.Errorf("expected %v, got %v", "Package-project1", rln.RefB) } if rln.Relationship != "DESCRIBES" { @@ -432,7 +432,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) { } config.TestValues["Created"] = "2018-10-19T04:38:00Z" - wantVerificationCode := spdx.PackageVerificationCode{Value: "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"} + wantVerificationCode := common.PackageVerificationCode{Value: "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"} doc, err := Build2_2("project1", dirRoot, config) if err != nil { @@ -452,7 +452,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) { if doc.DataLicense != "CC0-1.0" { t.Errorf("expected %s, got %s", "CC0-1.0", doc.DataLicense) } - if doc.SPDXIdentifier != spdx.ElementID("DOCUMENT") { + if doc.SPDXIdentifier != common.ElementID("DOCUMENT") { t.Errorf("expected %s, got %v", "DOCUMENT", doc.SPDXIdentifier) } if doc.DocumentName != "project1" { @@ -489,7 +489,7 @@ func TestBuild2_2CreatesDocument(t *testing.T) { if pkg.PackageName != "project1" { t.Errorf("expected %v, got %v", "project1", pkg.PackageName) } - if pkg.PackageSPDXIdentifier != spdx.ElementID("Package-project1") { + if pkg.PackageSPDXIdentifier != common.ElementID("Package-project1") { t.Errorf("expected %v, got %v", "Package-project1", pkg.PackageSPDXIdentifier) } if pkg.PackageDownloadLocation != "NOASSERTION" { @@ -534,20 +534,20 @@ func TestBuild2_2CreatesDocument(t *testing.T) { if fileEmpty.FileName != "./emptyfile.testdata.txt" { t.Errorf("expected %v, got %v", "./emptyfile.testdata.txt", fileEmpty.FileName) } - if fileEmpty.FileSPDXIdentifier != spdx.ElementID("File0") { + if fileEmpty.FileSPDXIdentifier != common.ElementID("File0") { t.Errorf("expected %v, got %v", "File0", fileEmpty.FileSPDXIdentifier) } for _, checksum := range fileEmpty.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "da39a3ee5e6b4b0d3255bfef95601890afd80709" { t.Errorf("expected %v, got %v", "da39a3ee5e6b4b0d3255bfef95601890afd80709", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" { t.Errorf("expected %v, got %v", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "d41d8cd98f00b204e9800998ecf8427e" { t.Errorf("expected %v, got %v", "d41d8cd98f00b204e9800998ecf8427e", checksum.Value) } @@ -575,20 +575,20 @@ func TestBuild2_2CreatesDocument(t *testing.T) { if file1.FileName != "./file1.testdata.txt" { t.Errorf("expected %v, got %v", "./file1.testdata.txt", file1.FileName) } - if file1.FileSPDXIdentifier != spdx.ElementID("File1") { + if file1.FileSPDXIdentifier != common.ElementID("File1") { t.Errorf("expected %v, got %v", "File1", file1.FileSPDXIdentifier) } for _, checksum := range file1.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "024f870eb6323f532515f7a09d5646a97083b819" { t.Errorf("expected %v, got %v", "024f870eb6323f532515f7a09d5646a97083b819", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf" { t.Errorf("expected %v, got %v", "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "37c8208479dfe42d2bb29debd6e32d4a" { t.Errorf("expected %v, got %v", "37c8208479dfe42d2bb29debd6e32d4a", checksum.Value) } @@ -616,20 +616,20 @@ func TestBuild2_2CreatesDocument(t *testing.T) { if file3.FileName != "./file3.testdata.txt" { t.Errorf("expected %v, got %v", "./file3.testdata.txt", file3.FileName) } - if file3.FileSPDXIdentifier != spdx.ElementID("File2") { + if file3.FileSPDXIdentifier != common.ElementID("File2") { t.Errorf("expected %v, got %v", "File2", file3.FileSPDXIdentifier) } for _, checksum := range file3.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "a46114b70e163614f01c64adf44cdd438f158fce" { t.Errorf("expected %v, got %v", "a46114b70e163614f01c64adf44cdd438f158fce", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "9fc181b9892720a15df1a1e561860318db40621bd4040ccdf18e110eb01d04b4" { t.Errorf("expected %v, got %v", "9fc181b9892720a15df1a1e561860318db40621bd4040ccdf18e110eb01d04b4", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "3e02d3ab9c58eec6911dbba37570934f" { t.Errorf("expected %v, got %v", "3e02d3ab9c58eec6911dbba37570934f", checksum.Value) } @@ -657,20 +657,20 @@ func TestBuild2_2CreatesDocument(t *testing.T) { if file4.FileName != "./folder1/file4.testdata.txt" { t.Errorf("expected %v, got %v", "./folder1/file4.testdata.txt", file4.FileName) } - if file4.FileSPDXIdentifier != spdx.ElementID("File3") { + if file4.FileSPDXIdentifier != common.ElementID("File3") { t.Errorf("expected %v, got %v", "File3", file4.FileSPDXIdentifier) } for _, checksum := range file4.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "e623d7d7d782a7c8323c4d436acee4afab34320f" { t.Errorf("expected %v, got %v", "e623d7d7d782a7c8323c4d436acee4afab34320f", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "574fa42c5e0806c0f8906a44884166540206f021527729407cd5326838629c59" { t.Errorf("expected %v, got %v", "574fa42c5e0806c0f8906a44884166540206f021527729407cd5326838629c59", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "96e6a25d35df5b1c477710ef4d0c7210" { t.Errorf("expected %v, got %v", "96e6a25d35df5b1c477710ef4d0c7210", checksum.Value) } @@ -698,20 +698,20 @@ func TestBuild2_2CreatesDocument(t *testing.T) { if lastfile.FileName != "./lastfile.testdata.txt" { t.Errorf("expected %v, got %v", "/lastfile.testdata.txt", lastfile.FileName) } - if lastfile.FileSPDXIdentifier != spdx.ElementID("File4") { + if lastfile.FileSPDXIdentifier != common.ElementID("File4") { t.Errorf("expected %v, got %v", "File4", lastfile.FileSPDXIdentifier) } for _, checksum := range lastfile.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "26d6221d682d9ba59116f9753a701f34271c8ce1" { t.Errorf("expected %v, got %v", "26d6221d682d9ba59116f9753a701f34271c8ce1", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "0a4bdaf990e9b330ff72022dd78110ae98b60e08337cf2105b89856373416805" { t.Errorf("expected %v, got %v", "0a4bdaf990e9b330ff72022dd78110ae98b60e08337cf2105b89856373416805", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "f60baa793870d9085461ad6bbab50b7f" { t.Errorf("expected %v, got %v", "f60baa793870d9085461ad6bbab50b7f", checksum.Value) } @@ -742,10 +742,10 @@ func TestBuild2_2CreatesDocument(t *testing.T) { if rln == nil { t.Fatalf("expected non-nil Relationship, got nil") } - if rln.RefA != spdx.MakeDocElementID("", "DOCUMENT") { + if rln.RefA != common.MakeDocElementID("", "DOCUMENT") { t.Errorf("expected %v, got %v", "DOCUMENT", rln.RefA) } - if rln.RefB != spdx.MakeDocElementID("", "Package-project1") { + if rln.RefB != common.MakeDocElementID("", "Package-project1") { t.Errorf("expected %v, got %v", "Package-project1", rln.RefB) } if rln.Relationship != "DESCRIBES" { diff --git a/builder/builder2v1/build_creation_info.go b/builder/builder2v1/build_creation_info.go index c838b92a..e128fb95 100644 --- a/builder/builder2v1/build_creation_info.go +++ b/builder/builder2v1/build_creation_info.go @@ -5,7 +5,8 @@ package builder2v1 import ( "time" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // BuildCreationInfoSection2_1 creates an SPDX Package (version 2.1), returning that @@ -13,9 +14,9 @@ import ( // - creatorType: one of Person, Organization or Tool // - creator: creator string // - testValues: for testing only; call with nil when using in production -func BuildCreationInfoSection2_1(creatorType string, creator string, testValues map[string]string) (*spdx.CreationInfo2_1, error) { +func BuildCreationInfoSection2_1(creatorType string, creator string, testValues map[string]string) (*v2_1.CreationInfo, error) { // build creator slices - creators := []spdx.Creator{ + creators := []common.Creator{ // add builder as a tool { Creator: "github.com/spdx/tools-golang/builder", @@ -35,7 +36,7 @@ func BuildCreationInfoSection2_1(creatorType string, creator string, testValues created = testVal } - ci := &spdx.CreationInfo2_1{ + ci := &v2_1.CreationInfo{ Creators: creators, Created: created, } diff --git a/builder/builder2v1/build_file.go b/builder/builder2v1/build_file.go index 7e9e52e3..57cc2bc9 100644 --- a/builder/builder2v1/build_file.go +++ b/builder/builder2v1/build_file.go @@ -6,7 +6,8 @@ import ( "fmt" "path/filepath" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" "github.com/spdx/tools-golang/utils" ) @@ -15,7 +16,7 @@ import ( // - filePath: path to file, relative to prefix // - prefix: relative directory for filePath // - fileNumber: integer index (unique within package) to use in identifier -func BuildFileSection2_1(filePath string, prefix string, fileNumber int) (*spdx.File2_1, error) { +func BuildFileSection2_1(filePath string, prefix string, fileNumber int) (*v2_1.File, error) { // build the full file path p := filepath.Join(prefix, filePath) @@ -29,20 +30,20 @@ func BuildFileSection2_1(filePath string, prefix string, fileNumber int) (*spdx. i := fmt.Sprintf("File%d", fileNumber) // now build the File section - f := &spdx.File2_1{ + f := &v2_1.File{ FileName: filePath, - FileSPDXIdentifier: spdx.ElementID(i), - Checksums: []spdx.Checksum{ + FileSPDXIdentifier: common.ElementID(i), + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: ssha1, }, { - Algorithm: spdx.SHA256, + Algorithm: common.SHA256, Value: ssha256, }, { - Algorithm: spdx.MD5, + Algorithm: common.MD5, Value: smd5, }, }, diff --git a/builder/builder2v1/build_file_test.go b/builder/builder2v1/build_file_test.go index cea297b2..5da0390b 100644 --- a/builder/builder2v1/build_file_test.go +++ b/builder/builder2v1/build_file_test.go @@ -5,7 +5,7 @@ package builder2v1 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" ) // ===== File section builder tests ===== @@ -25,21 +25,21 @@ func TestBuilder2_1CanBuildFileSection(t *testing.T) { if file1.FileName != "/file1.testdata.txt" { t.Errorf("expected %v, got %v", "/file1.testdata.txt", file1.FileName) } - if file1.FileSPDXIdentifier != spdx.ElementID("File17") { + if file1.FileSPDXIdentifier != common.ElementID("File17") { t.Errorf("expected %v, got %v", "File17", file1.FileSPDXIdentifier) } for _, checksum := range file1.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "024f870eb6323f532515f7a09d5646a97083b819" { t.Errorf("expected %v, got %v", "024f870eb6323f532515f7a09d5646a97083b819", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf" { t.Errorf("expected %v, got %v", "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "37c8208479dfe42d2bb29debd6e32d4a" { t.Errorf("expected %v, got %v", "37c8208479dfe42d2bb29debd6e32d4a", checksum.Value) } diff --git a/builder/builder2v1/build_package.go b/builder/builder2v1/build_package.go index f39bb536..7d8ddbb1 100644 --- a/builder/builder2v1/build_package.go +++ b/builder/builder2v1/build_package.go @@ -4,11 +4,13 @@ package builder2v1 import ( "fmt" - "github.com/spdx/tools-golang/spdx" - "github.com/spdx/tools-golang/utils" "path/filepath" "regexp" "runtime" + + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/utils" ) // BuildPackageSection2_1 creates an SPDX Package (version 2.1), returning @@ -16,7 +18,7 @@ import ( // - packageName: name of package / directory // - dirRoot: path to directory to be analyzed // - pathsIgnore: slice of strings for filepaths to ignore -func BuildPackageSection2_1(packageName string, dirRoot string, pathsIgnore []string) (*spdx.Package2_1, error) { +func BuildPackageSection2_1(packageName string, dirRoot string, pathsIgnore []string) (*v2_1.Package, error) { // build the file section first, so we'll have it available // for calculating the package verification code filepaths, err := utils.GetAllFilePaths(dirRoot, pathsIgnore) @@ -35,7 +37,7 @@ func BuildPackageSection2_1(packageName string, dirRoot string, pathsIgnore []st dirRootLen = len(dirRoot) } - files := []*spdx.File2_1{} + files := []*v2_1.File{} fileNumber := 0 for _, fp := range filepaths { newFilePatch := "" @@ -58,9 +60,9 @@ func BuildPackageSection2_1(packageName string, dirRoot string, pathsIgnore []st } // now build the package section - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: packageName, - PackageSPDXIdentifier: spdx.ElementID(fmt.Sprintf("Package-%s", packageName)), + PackageSPDXIdentifier: common.ElementID(fmt.Sprintf("Package-%s", packageName)), PackageDownloadLocation: "NOASSERTION", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, diff --git a/builder/builder2v1/build_package_test.go b/builder/builder2v1/build_package_test.go index 14586371..959ae651 100644 --- a/builder/builder2v1/build_package_test.go +++ b/builder/builder2v1/build_package_test.go @@ -5,7 +5,7 @@ package builder2v1 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" ) // ===== Package section builder tests ===== @@ -13,7 +13,7 @@ func TestBuilder2_1CanBuildPackageSection(t *testing.T) { packageName := "project1" dirRoot := "../../testdata/project1/" - wantVerificationCode := spdx.PackageVerificationCode{Value: "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"} + wantVerificationCode := common.PackageVerificationCode{Value: "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"} pkg, err := BuildPackageSection2_1(packageName, dirRoot, nil) if err != nil { @@ -26,7 +26,7 @@ func TestBuilder2_1CanBuildPackageSection(t *testing.T) { if pkg.PackageName != "project1" { t.Errorf("expected %v, got %v", "project1", pkg.PackageName) } - if pkg.PackageSPDXIdentifier != spdx.ElementID("Package-project1") { + if pkg.PackageSPDXIdentifier != common.ElementID("Package-project1") { t.Errorf("expected %v, got %v", "Package-project1", pkg.PackageSPDXIdentifier) } if pkg.PackageDownloadLocation != "NOASSERTION" { @@ -68,20 +68,20 @@ func TestBuilder2_1CanBuildPackageSection(t *testing.T) { if fileEmpty.FileName != "./emptyfile.testdata.txt" { t.Errorf("expected %v, got %v", "./emptyfile.testdata.txt", fileEmpty.FileName) } - if fileEmpty.FileSPDXIdentifier != spdx.ElementID("File0") { + if fileEmpty.FileSPDXIdentifier != common.ElementID("File0") { t.Errorf("expected %v, got %v", "File0", fileEmpty.FileSPDXIdentifier) } for _, checksum := range fileEmpty.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "da39a3ee5e6b4b0d3255bfef95601890afd80709" { t.Errorf("expected %v, got %v", "da39a3ee5e6b4b0d3255bfef95601890afd80709", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" { t.Errorf("expected %v, got %v", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "d41d8cd98f00b204e9800998ecf8427e" { t.Errorf("expected %v, got %v", "d41d8cd98f00b204e9800998ecf8427e", checksum.Value) } diff --git a/builder/builder2v1/build_relationship.go b/builder/builder2v1/build_relationship.go index 7c780e6f..9f11d583 100644 --- a/builder/builder2v1/build_relationship.go +++ b/builder/builder2v1/build_relationship.go @@ -5,17 +5,18 @@ package builder2v1 import ( "fmt" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // BuildRelationshipSection2_1 creates an SPDX Relationship (version 2.1) // solely for the document "DESCRIBES" package relationship, returning that // relationship or error if any is encountered. Arguments: // - packageName: name of package / directory -func BuildRelationshipSection2_1(packageName string) (*spdx.Relationship2_1, error) { - rln := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", fmt.Sprintf("Package-%s", packageName)), +func BuildRelationshipSection2_1(packageName string) (*v2_1.Relationship, error) { + rln := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", fmt.Sprintf("Package-%s", packageName)), Relationship: "DESCRIBES", } diff --git a/builder/builder2v1/build_relationship_test.go b/builder/builder2v1/build_relationship_test.go index 384f5b39..a24dedcd 100644 --- a/builder/builder2v1/build_relationship_test.go +++ b/builder/builder2v1/build_relationship_test.go @@ -5,7 +5,7 @@ package builder2v1 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" ) // ===== Relationship section builder tests ===== @@ -20,10 +20,10 @@ func TestBuilder2_1CanBuildRelationshipSection(t *testing.T) { if rln == nil { t.Fatalf("expected non-nil relationship, got nil") } - if rln.RefA != spdx.MakeDocElementID("", "DOCUMENT") { + if rln.RefA != common.MakeDocElementID("", "DOCUMENT") { t.Errorf("expected %v, got %v", "DOCUMENT", rln.RefA) } - if rln.RefB != spdx.MakeDocElementID("", "Package-project17") { + if rln.RefB != common.MakeDocElementID("", "Package-project17") { t.Errorf("expected %v, got %v", "Package-project17", rln.RefB) } if rln.Relationship != "DESCRIBES" { diff --git a/builder/builder2v2/build_creation_info.go b/builder/builder2v2/build_creation_info.go index c24d2d31..74b43fb5 100644 --- a/builder/builder2v2/build_creation_info.go +++ b/builder/builder2v2/build_creation_info.go @@ -5,7 +5,8 @@ package builder2v2 import ( "time" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // BuildCreationInfoSection2_2 creates an SPDX Package (version 2.2), returning that @@ -16,9 +17,9 @@ import ( // - creatorType: one of Person, Organization or Tool // - creator: creator string // - testValues: for testing only; call with nil when using in production -func BuildCreationInfoSection2_2(creatorType string, creator string, testValues map[string]string) (*spdx.CreationInfo2_2, error) { +func BuildCreationInfoSection2_2(creatorType string, creator string, testValues map[string]string) (*v2_2.CreationInfo, error) { // build creator slices - creators := []spdx.Creator{ + creators := []common.Creator{ // add builder as a tool { Creator: "github.com/spdx/tools-golang/builder", @@ -38,7 +39,7 @@ func BuildCreationInfoSection2_2(creatorType string, creator string, testValues created = testVal } - ci := &spdx.CreationInfo2_2{ + ci := &v2_2.CreationInfo{ Creators: creators, Created: created, } diff --git a/builder/builder2v2/build_file.go b/builder/builder2v2/build_file.go index efdd9799..4e69f58b 100644 --- a/builder/builder2v2/build_file.go +++ b/builder/builder2v2/build_file.go @@ -6,7 +6,8 @@ import ( "fmt" "path/filepath" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" "github.com/spdx/tools-golang/utils" ) @@ -15,7 +16,7 @@ import ( // - filePath: path to file, relative to prefix // - prefix: relative directory for filePath // - fileNumber: integer index (unique within package) to use in identifier -func BuildFileSection2_2(filePath string, prefix string, fileNumber int) (*spdx.File2_2, error) { +func BuildFileSection2_2(filePath string, prefix string, fileNumber int) (*v2_2.File, error) { // build the full file path p := filepath.Join(prefix, filePath) @@ -29,20 +30,20 @@ func BuildFileSection2_2(filePath string, prefix string, fileNumber int) (*spdx. i := fmt.Sprintf("File%d", fileNumber) // now build the File section - f := &spdx.File2_2{ + f := &v2_2.File{ FileName: filePath, - FileSPDXIdentifier: spdx.ElementID(i), - Checksums: []spdx.Checksum{ + FileSPDXIdentifier: common.ElementID(i), + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: ssha1, }, { - Algorithm: spdx.SHA256, + Algorithm: common.SHA256, Value: ssha256, }, { - Algorithm: spdx.MD5, + Algorithm: common.MD5, Value: smd5, }, }, diff --git a/builder/builder2v2/build_file_test.go b/builder/builder2v2/build_file_test.go index 74a6a6a9..86915837 100644 --- a/builder/builder2v2/build_file_test.go +++ b/builder/builder2v2/build_file_test.go @@ -5,7 +5,7 @@ package builder2v2 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" ) // ===== File section builder tests ===== @@ -25,21 +25,21 @@ func TestBuilder2_2CanBuildFileSection(t *testing.T) { if file1.FileName != "/file1.testdata.txt" { t.Errorf("expected %v, got %v", "/file1.testdata.txt", file1.FileName) } - if file1.FileSPDXIdentifier != spdx.ElementID("File17") { + if file1.FileSPDXIdentifier != common.ElementID("File17") { t.Errorf("expected %v, got %v", "File17", file1.FileSPDXIdentifier) } for _, checksum := range file1.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "024f870eb6323f532515f7a09d5646a97083b819" { t.Errorf("expected %v, got %v", "024f870eb6323f532515f7a09d5646a97083b819", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf" { t.Errorf("expected %v, got %v", "b14e44284ca477b4c0db34b15ca4c454b2947cce7883e22321cf2984050e15bf", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "37c8208479dfe42d2bb29debd6e32d4a" { t.Errorf("expected %v, got %v", "37c8208479dfe42d2bb29debd6e32d4a", checksum.Value) } diff --git a/builder/builder2v2/build_package.go b/builder/builder2v2/build_package.go index 9c460da8..7cccf630 100644 --- a/builder/builder2v2/build_package.go +++ b/builder/builder2v2/build_package.go @@ -4,11 +4,13 @@ package builder2v2 import ( "fmt" - "github.com/spdx/tools-golang/spdx" - "github.com/spdx/tools-golang/utils" "path/filepath" "regexp" "runtime" + + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" + "github.com/spdx/tools-golang/utils" ) // BuildPackageSection2_2 creates an SPDX Package (version 2.2), returning @@ -16,7 +18,7 @@ import ( // - packageName: name of package / directory // - dirRoot: path to directory to be analyzed // - pathsIgnore: slice of strings for filepaths to ignore -func BuildPackageSection2_2(packageName string, dirRoot string, pathsIgnore []string) (*spdx.Package2_2, error) { +func BuildPackageSection2_2(packageName string, dirRoot string, pathsIgnore []string) (*v2_2.Package, error) { // build the file section first, so we'll have it available // for calculating the package verification code filepaths, err := utils.GetAllFilePaths(dirRoot, pathsIgnore) @@ -35,7 +37,7 @@ func BuildPackageSection2_2(packageName string, dirRoot string, pathsIgnore []st dirRootLen = len(dirRoot) } - files := []*spdx.File2_2{} + files := []*v2_2.File{} fileNumber := 0 for _, fp := range filepaths { newFilePatch := "" @@ -59,9 +61,9 @@ func BuildPackageSection2_2(packageName string, dirRoot string, pathsIgnore []st } // now build the package section - pkg := &spdx.Package2_2{ + pkg := &v2_2.Package{ PackageName: packageName, - PackageSPDXIdentifier: spdx.ElementID(fmt.Sprintf("Package-%s", packageName)), + PackageSPDXIdentifier: common.ElementID(fmt.Sprintf("Package-%s", packageName)), PackageDownloadLocation: "NOASSERTION", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, diff --git a/builder/builder2v2/build_package_test.go b/builder/builder2v2/build_package_test.go index 3ab88d24..8a214163 100644 --- a/builder/builder2v2/build_package_test.go +++ b/builder/builder2v2/build_package_test.go @@ -5,7 +5,7 @@ package builder2v2 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" ) // ===== Package section builder tests ===== @@ -13,7 +13,7 @@ func TestBuilder2_2CanBuildPackageSection(t *testing.T) { packageName := "project1" dirRoot := "../../testdata/project1/" - wantVerificationCode := spdx.PackageVerificationCode{Value: "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"} + wantVerificationCode := common.PackageVerificationCode{Value: "fc9ac4a370af0a471c2e52af66d6b4cf4e2ba12b"} pkg, err := BuildPackageSection2_2(packageName, dirRoot, nil) if err != nil { @@ -26,7 +26,7 @@ func TestBuilder2_2CanBuildPackageSection(t *testing.T) { if pkg.PackageName != "project1" { t.Errorf("expected %v, got %v", "project1", pkg.PackageName) } - if pkg.PackageSPDXIdentifier != spdx.ElementID("Package-project1") { + if pkg.PackageSPDXIdentifier != common.ElementID("Package-project1") { t.Errorf("expected %v, got %v", "Package-project1", pkg.PackageSPDXIdentifier) } if pkg.PackageDownloadLocation != "NOASSERTION" { @@ -68,20 +68,20 @@ func TestBuilder2_2CanBuildPackageSection(t *testing.T) { if fileEmpty.FileName != "./emptyfile.testdata.txt" { t.Errorf("expected %v, got %v", "./emptyfile.testdata.txt", fileEmpty.FileName) } - if fileEmpty.FileSPDXIdentifier != spdx.ElementID("File0") { + if fileEmpty.FileSPDXIdentifier != common.ElementID("File0") { t.Errorf("expected %v, got %v", "File0", fileEmpty.FileSPDXIdentifier) } for _, checksum := range fileEmpty.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "da39a3ee5e6b4b0d3255bfef95601890afd80709" { t.Errorf("expected %v, got %v", "da39a3ee5e6b4b0d3255bfef95601890afd80709", checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" { t.Errorf("expected %v, got %v", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != "d41d8cd98f00b204e9800998ecf8427e" { t.Errorf("expected %v, got %v", "d41d8cd98f00b204e9800998ecf8427e", checksum.Value) } diff --git a/builder/builder2v2/build_relationship.go b/builder/builder2v2/build_relationship.go index 5eaf9dea..1dd8f2b0 100644 --- a/builder/builder2v2/build_relationship.go +++ b/builder/builder2v2/build_relationship.go @@ -5,17 +5,18 @@ package builder2v2 import ( "fmt" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // BuildRelationshipSection2_2 creates an SPDX Relationship (version 2.2) // solely for the document "DESCRIBES" package relationship, returning that // relationship or error if any is encountered. Arguments: // - packageName: name of package / directory -func BuildRelationshipSection2_2(packageName string) (*spdx.Relationship2_2, error) { - rln := &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", fmt.Sprintf("Package-%s", packageName)), +func BuildRelationshipSection2_2(packageName string) (*v2_2.Relationship, error) { + rln := &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", fmt.Sprintf("Package-%s", packageName)), Relationship: "DESCRIBES", } diff --git a/builder/builder2v2/build_relationship_test.go b/builder/builder2v2/build_relationship_test.go index 4e8ba99e..126ddbea 100644 --- a/builder/builder2v2/build_relationship_test.go +++ b/builder/builder2v2/build_relationship_test.go @@ -5,7 +5,7 @@ package builder2v2 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" ) // ===== Relationship section builder tests ===== @@ -20,10 +20,10 @@ func TestBuilder2_2CanBuildRelationshipSection(t *testing.T) { if rln == nil { t.Fatalf("expected non-nil relationship, got nil") } - if rln.RefA != spdx.MakeDocElementID("", "DOCUMENT") { + if rln.RefA != common.MakeDocElementID("", "DOCUMENT") { t.Errorf("expected %v, got %v", "DOCUMENT", rln.RefA) } - if rln.RefB != spdx.MakeDocElementID("", "Package-project17") { + if rln.RefB != common.MakeDocElementID("", "Package-project17") { t.Errorf("expected %v, got %v", "Package-project17", rln.RefB) } if rln.Relationship != "DESCRIBES" { diff --git a/docs/jsonloader.md b/docs/jsonloader.md index 5f11ccbb..3d6b1b18 100644 --- a/docs/jsonloader.md +++ b/docs/jsonloader.md @@ -2,9 +2,9 @@ SPDX-License-Identifier: CC-BY-4.0 ## Usage -A json.Unmarshal function on the spdx.Document2_2 struct is defined so that when the JSON is unmarshalled, the function is called and the JSON can be processed in a custom way. Then a new map[string]interface{} is defined which temporarily holds the unmarshalled JSON. The map is then parsed into the spdx.Document2_2 using functions defined for each different section. +A json.Unmarshal function on the v2_2.Document struct is defined so that when the JSON is unmarshalled, the function is called and the JSON can be processed in a custom way. Then a new map[string]interface{} is defined which temporarily holds the unmarshalled JSON. The map is then parsed into the v2_2.Document using functions defined for each different section. -JSON => map[string]interface{} => spdx.Document2_2 +JSON => map[string]interface{} => v2_2.Document ## Some Key Points diff --git a/docs/jsonsaver.md b/docs/jsonsaver.md index fe9d34f8..bd6f95f5 100644 --- a/docs/jsonsaver.md +++ b/docs/jsonsaver.md @@ -4,7 +4,7 @@ SPDX-License-Identifier: CC-BY-4.0 The SPDX document is converted to map[string]interface{} and then the entire map is converted to JSON using a single json.MarshalIndent function call. The saver uses temporary memory to store all the files (Packaged and Unpackaged) together in a single data structure in order to comply with the JSON schema defined by SPDX. -spdx.Document2_2 => map[string]interface{} => JSON +v2_2.Document => map[string]interface{} => JSON ## Some Key Points diff --git a/examples/10-jsonloader/example_json_loader.go b/examples/10-jsonloader/example_json_loader.go index 793f10ee..1ccf4d0f 100644 --- a/examples/10-jsonloader/example_json_loader.go +++ b/examples/10-jsonloader/example_json_loader.go @@ -12,7 +12,7 @@ import ( "os" "strings" - "github.com/spdx/tools-golang/json" + spdx_json "github.com/spdx/tools-golang/json" ) func main() { diff --git a/examples/11-yamltotv/exampleyamltotv.go b/examples/11-yamltotv/exampleyamltotv.go index b56a67db..d14201c3 100644 --- a/examples/11-yamltotv/exampleyamltotv.go +++ b/examples/11-yamltotv/exampleyamltotv.go @@ -10,9 +10,10 @@ package main import ( "fmt" - "github.com/spdx/tools-golang/tvsaver" - "github.com/spdx/tools-golang/yaml" "os" + + "github.com/spdx/tools-golang/tvsaver" + spdx_yaml "github.com/spdx/tools-golang/yaml" ) func main() { diff --git a/examples/12-tvtoyaml/exampletvtoyaml.go b/examples/12-tvtoyaml/exampletvtoyaml.go index 1f43a031..19abde70 100644 --- a/examples/12-tvtoyaml/exampletvtoyaml.go +++ b/examples/12-tvtoyaml/exampletvtoyaml.go @@ -12,7 +12,7 @@ import ( "os" "github.com/spdx/tools-golang/tvloader" - "github.com/spdx/tools-golang/yaml" + spdx_yaml "github.com/spdx/tools-golang/yaml" ) func main() { diff --git a/examples/13-yamlloader/exampleYAMLLoader.go b/examples/13-yamlloader/exampleYAMLLoader.go index 237cc659..a032eceb 100644 --- a/examples/13-yamlloader/exampleYAMLLoader.go +++ b/examples/13-yamlloader/exampleYAMLLoader.go @@ -12,7 +12,7 @@ import ( "os" "strings" - "github.com/spdx/tools-golang/yaml" + spdx_yaml "github.com/spdx/tools-golang/yaml" ) func main() { diff --git a/examples/6-licensediff/example_licensediff.go b/examples/6-licensediff/example_licensediff.go index 49d76035..39c369d2 100644 --- a/examples/6-licensediff/example_licensediff.go +++ b/examples/6-licensediff/example_licensediff.go @@ -13,10 +13,10 @@ package main import ( "fmt" - "github.com/spdx/tools-golang/spdx" "os" "github.com/spdx/tools-golang/licensediff" + "github.com/spdx/tools-golang/spdx/v2_2" "github.com/spdx/tools-golang/spdxlib" "github.com/spdx/tools-golang/tvloader" ) @@ -87,7 +87,7 @@ func main() { for _, pkgID := range pkgIDsFirst { fmt.Printf("================================\n") - var p1, p2 *spdx.Package2_2 + var p1, p2 *v2_2.Package var okFirst, okSecond bool for _, pkg := range docFirst.Packages { if pkg.PackageSPDXIdentifier == pkgID { @@ -139,7 +139,7 @@ func main() { // now report if there are any package IDs in the second set that aren't // in the first for _, pkgID := range pkgIDsSecond { - var p2 *spdx.Package2_2 + var p2 *v2_2.Package var okFirst, okSecond bool for _, pkg := range docSecond.Packages { if pkg.PackageSPDXIdentifier == pkgID { diff --git a/examples/7-rdfloader/exampleRDFLoader.go b/examples/7-rdfloader/exampleRDFLoader.go index 5258ac2b..81206a43 100644 --- a/examples/7-rdfloader/exampleRDFLoader.go +++ b/examples/7-rdfloader/exampleRDFLoader.go @@ -4,9 +4,10 @@ package main import ( "fmt" - "github.com/spdx/tools-golang/rdfloader" "os" "strings" + + "github.com/spdx/tools-golang/rdfloader" ) func getFilePathFromUser() (string, error) { diff --git a/examples/8-jsontotv/examplejsontotv.go b/examples/8-jsontotv/examplejsontotv.go index 85be2827..ee10bd27 100644 --- a/examples/8-jsontotv/examplejsontotv.go +++ b/examples/8-jsontotv/examplejsontotv.go @@ -11,7 +11,7 @@ import ( "fmt" "os" - "github.com/spdx/tools-golang/json" + spdx_json "github.com/spdx/tools-golang/json" "github.com/spdx/tools-golang/tvsaver" ) diff --git a/examples/9-tvtojson/exampletvtojson.go b/examples/9-tvtojson/exampletvtojson.go index e8e6937a..909677ff 100644 --- a/examples/9-tvtojson/exampletvtojson.go +++ b/examples/9-tvtojson/exampletvtojson.go @@ -11,7 +11,7 @@ import ( "fmt" "os" - "github.com/spdx/tools-golang/json" + spdx_json "github.com/spdx/tools-golang/json" "github.com/spdx/tools-golang/tvloader" ) diff --git a/idsearcher/idsearcher.go b/idsearcher/idsearcher.go index bb8bbd1a..29b0faa2 100644 --- a/idsearcher/idsearcher.go +++ b/idsearcher/idsearcher.go @@ -14,7 +14,8 @@ import ( "strings" "github.com/spdx/tools-golang/builder" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" "github.com/spdx/tools-golang/utils" ) @@ -50,7 +51,7 @@ type Config2_1 struct { // - dirRoot: path to directory to be analyzed // - namespacePrefix: URI representing a prefix for the // namespace with which the SPDX Document will be associated -func BuildIDsDocument2_1(packageName string, dirRoot string, idconfig *Config2_1) (*spdx.Document2_1, error) { +func BuildIDsDocument2_1(packageName string, dirRoot string, idconfig *Config2_1) (*v2_1.Document, error) { // first, build the Document using builder bconfig := &builder.Config2_1{ NamespacePrefix: idconfig.NamespacePrefix, @@ -174,7 +175,7 @@ type Config2_2 struct { // - dirRoot: path to directory to be analyzed // - namespacePrefix: URI representing a prefix for the // namespace with which the SPDX Document will be associated -func BuildIDsDocument2_2(packageName string, dirRoot string, idconfig *Config2_2) (*spdx.Document2_2, error) { +func BuildIDsDocument2_2(packageName string, dirRoot string, idconfig *Config2_2) (*v2_2.Document, error) { // first, build the Document using builder bconfig := &builder.Config2_2{ NamespacePrefix: idconfig.NamespacePrefix, diff --git a/json/json_test.go b/json/json_test.go index c78013cb..2c22dcd4 100644 --- a/json/json_test.go +++ b/json/json_test.go @@ -5,11 +5,13 @@ package spdx_json import ( "bytes" "fmt" - "github.com/google/go-cmp/cmp" "os" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/google/go-cmp/cmp" + + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) func TestLoad2_2(t *testing.T) { @@ -58,15 +60,15 @@ func TestWrite2_2(t *testing.T) { // want is handwritten translation of the official example JSON SPDX v2.2 document into a Go struct. // We expect that the result of parsing the official document should be this value. // We expect that the result of writing this struct should match the official example document. -var want = spdx.Document2_2{ +var want = v2_2.Document{ DataLicense: "CC0-1.0", SPDXVersion: "SPDX-2.2", SPDXIdentifier: "SPDXRef-DOCUMENT", DocumentName: "SPDX-Tools-v2.0", DocumentNamespace: "http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301", - CreationInfo: &spdx.CreationInfo2_2{ + CreationInfo: &v2_2.CreationInfo{ LicenseListVersion: "3.9", - Creators: []spdx.Creator{ + Creators: []common.Creator{ {CreatorType: "Tool", Creator: "LicenseFind-1.0"}, {CreatorType: "Organization", Creator: "ExampleCodeInspect ()"}, {CreatorType: "Person", Creator: "Jane Doe ()"}, @@ -75,17 +77,17 @@ var want = spdx.Document2_2{ CreatorComment: "This package has been shipped in source and binary form.\nThe binaries were created with gcc 4.5.1 and expect to link to\ncompatible system run time libraries.", }, DocumentComment: "This document was created using SPDX 2.0 using licenses from the web site.", - ExternalDocumentReferences: []spdx.ExternalDocumentRef2_2{ + ExternalDocumentReferences: []v2_2.ExternalDocumentRef{ { DocumentRefID: "DocumentRef-spdx-tool-1.2", URI: "http://spdx.org/spdxdocs/spdx-tools-v1.2-3F2504E0-4F89-41D3-9A0C-0305E82C3301", - Checksum: spdx.Checksum{ - Algorithm: spdx.SHA1, + Checksum: common.Checksum{ + Algorithm: common.SHA1, Value: "d6a770ba38583ed4bb4525bd96e50461655d2759", }, }, }, - OtherLicenses: []*spdx.OtherLicense2_2{ + OtherLicenses: []*v2_2.OtherLicense{ { LicenseIdentifier: "LicenseRef-1", ExtractedText: "/*\n * (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * 3. The name of the author may not be used to endorse or promote products\n * derived from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\n * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*/", @@ -116,9 +118,9 @@ var want = spdx.Document2_2{ LicenseComment: "This is tye CyperNeko License", }, }, - Annotations: []*spdx.Annotation2_2{ + Annotations: []*v2_2.Annotation{ { - Annotator: spdx.Annotator{ + Annotator: common.Annotator{ Annotator: "Jane Doe ()", AnnotatorType: "Person", }, @@ -127,7 +129,7 @@ var want = spdx.Document2_2{ AnnotationComment: "Document level annotation", }, { - Annotator: spdx.Annotator{ + Annotator: common.Annotator{ Annotator: "Joe Reviewer", AnnotatorType: "Person", }, @@ -136,7 +138,7 @@ var want = spdx.Document2_2{ AnnotationComment: "This is just an example. Some of the non-standard licenses look like they are actually BSD 3 clause licenses", }, { - Annotator: spdx.Annotator{ + Annotator: common.Annotator{ Annotator: "Suzanne Reviewer", AnnotatorType: "Person", }, @@ -145,27 +147,27 @@ var want = spdx.Document2_2{ AnnotationComment: "Another example reviewer.", }, }, - Packages: []*spdx.Package2_2{ + Packages: []*v2_2.Package{ { PackageName: "glibc", PackageSPDXIdentifier: "SPDXRef-Package", PackageVersion: "2.11.1", PackageFileName: "glibc-2.11.1.tar.gz", - PackageSupplier: &spdx.Supplier{ + PackageSupplier: &common.Supplier{ Supplier: "Jane Doe (jane.doe@example.com)", SupplierType: "Person", }, - PackageOriginator: &spdx.Originator{ + PackageOriginator: &common.Originator{ Originator: "ExampleCodeInspect (contact@example.com)", OriginatorType: "Organization", }, PackageDownloadLocation: "http://ftp.gnu.org/gnu/glibc/glibc-ports-2.15.tar.gz", FilesAnalyzed: true, - PackageVerificationCode: spdx.PackageVerificationCode{ + PackageVerificationCode: common.PackageVerificationCode{ Value: "d6a770ba38583ed4bb4525bd96e50461655d2758", ExcludedFiles: []string{"./package.spdx"}, }, - PackageChecksums: []spdx.Checksum{ + PackageChecksums: []common.Checksum{ { Algorithm: "MD5", Value: "624c1abb3664f4b35547e7c73864ad24", @@ -193,7 +195,7 @@ var want = spdx.Document2_2{ PackageSummary: "GNU C library.", PackageDescription: "The GNU C Library defines functions that are specified by the ISO C standard, as well as additional features specific to POSIX and other derivatives of the Unix operating system, and extensions specific to GNU systems.", PackageComment: "", - PackageExternalReferences: []*spdx.PackageExternalReference2_2{ + PackageExternalReferences: []*v2_2.PackageExternalReference{ { Category: "SECURITY", RefType: "cpe23Type", @@ -210,9 +212,9 @@ var want = spdx.Document2_2{ "The GNU C Library is free software. See the file COPYING.LIB for copying conditions, and LICENSES for notices about a few contributions that require these additional notices to be distributed. License copyright years may be listed using range notation, e.g., 1996-2015, indicating that every year in the range, inclusive, is a copyrightable year that would otherwise be listed individually.", }, Files: nil, - Annotations: []spdx.Annotation2_2{ + Annotations: []v2_2.Annotation{ { - Annotator: spdx.Annotator{ + Annotator: common.Annotator{ Annotator: "Package Commenter", AnnotatorType: "Person", }, @@ -237,7 +239,7 @@ var want = spdx.Document2_2{ PackageSPDXIdentifier: "SPDXRef-fromDoap-0", PackageCopyrightText: "NOASSERTION", PackageDownloadLocation: "https://search.maven.org/remotecontent?filepath=org/apache/jena/apache-jena/3.12.0/apache-jena-3.12.0.tar.gz", - PackageExternalReferences: []*spdx.PackageExternalReference2_2{ + PackageExternalReferences: []*v2_2.PackageExternalReference{ { Category: "PACKAGE_MANAGER", RefType: "purl", @@ -252,7 +254,7 @@ var want = spdx.Document2_2{ }, { PackageSPDXIdentifier: "SPDXRef-Saxon", - PackageChecksums: []spdx.Checksum{ + PackageChecksums: []common.Checksum{ { Algorithm: "SHA1", Value: "85ed0817af83a24ad8da68c2b5094de69833983c", @@ -271,14 +273,14 @@ var want = spdx.Document2_2{ PackageVersion: "8.8", }, }, - Files: []*spdx.File2_2{ + Files: []*v2_2.File{ { FileName: "./src/org/spdx/parser/DOAPProject.java", FileSPDXIdentifier: "SPDXRef-DoapSource", FileTypes: []string{ "SOURCE", }, - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { Algorithm: "SHA1", Value: "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", @@ -299,7 +301,7 @@ var want = spdx.Document2_2{ }, { FileSPDXIdentifier: "SPDXRef-CommonsLangSrc", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { Algorithm: "SHA1", Value: "c2b4e1c67a2d28fced849ee1bb76e7391b93f125", @@ -316,7 +318,7 @@ var want = spdx.Document2_2{ }, { FileSPDXIdentifier: "SPDXRef-JenaLib", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { Algorithm: "SHA1", Value: "3ab4e1c67a2d28fced849ee1bb76e7391b93f125", @@ -333,9 +335,9 @@ var want = spdx.Document2_2{ }, { FileSPDXIdentifier: "SPDXRef-File", - Annotations: []spdx.Annotation2_2{ + Annotations: []v2_2.Annotation{ { - Annotator: spdx.Annotator{ + Annotator: common.Annotator{ Annotator: "File Commenter", AnnotatorType: "Person", }, @@ -344,7 +346,7 @@ var want = spdx.Document2_2{ AnnotationComment: "File level annotation", }, }, - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { Algorithm: "SHA1", Value: "d6a770ba38583ed4bb4525bd96e50461655d2758", @@ -365,27 +367,27 @@ var want = spdx.Document2_2{ FileNotice: "Copyright (c) 2001 Aaron Lehmann aaroni@vitelus.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the �Software�), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: \nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED �AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", }, }, - Snippets: []spdx.Snippet2_2{ + Snippets: []v2_2.Snippet{ { SnippetSPDXIdentifier: "SPDXRef-Snippet", SnippetFromFileSPDXIdentifier: "SPDXRef-DoapSource", - Ranges: []spdx.SnippetRange{ + Ranges: []common.SnippetRange{ { - StartPointer: spdx.SnippetRangePointer{ + StartPointer: common.SnippetRangePointer{ Offset: 310, FileSPDXIdentifier: "SPDXRef-DoapSource", }, - EndPointer: spdx.SnippetRangePointer{ + EndPointer: common.SnippetRangePointer{ Offset: 420, FileSPDXIdentifier: "SPDXRef-DoapSource", }, }, { - StartPointer: spdx.SnippetRangePointer{ + StartPointer: common.SnippetRangePointer{ LineNumber: 5, FileSPDXIdentifier: "SPDXRef-DoapSource", }, - EndPointer: spdx.SnippetRangePointer{ + EndPointer: common.SnippetRangePointer{ LineNumber: 23, FileSPDXIdentifier: "SPDXRef-DoapSource", }, @@ -399,50 +401,50 @@ var want = spdx.Document2_2{ SnippetName: "from linux kernel", }, }, - Relationships: []*spdx.Relationship2_2{ + Relationships: []*v2_2.Relationship{ { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "Package"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "Package"), Relationship: "CONTAINS", }, { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("spdx-tool-1.2", "ToolsElement"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("spdx-tool-1.2", "ToolsElement"), Relationship: "COPY_OF", }, { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "File"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "File"), Relationship: "DESCRIBES", }, { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "Package"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "Package"), Relationship: "DESCRIBES", }, { - RefA: spdx.MakeDocElementID("", "Package"), - RefB: spdx.MakeDocElementID("", "JenaLib"), + RefA: common.MakeDocElementID("", "Package"), + RefB: common.MakeDocElementID("", "JenaLib"), Relationship: "CONTAINS", }, { - RefA: spdx.MakeDocElementID("", "Package"), - RefB: spdx.MakeDocElementID("", "Saxon"), + RefA: common.MakeDocElementID("", "Package"), + RefB: common.MakeDocElementID("", "Saxon"), Relationship: "DYNAMIC_LINK", }, { - RefA: spdx.MakeDocElementID("", "CommonsLangSrc"), - RefB: spdx.MakeDocElementSpecial("NOASSERTION"), + RefA: common.MakeDocElementID("", "CommonsLangSrc"), + RefB: common.MakeDocElementSpecial("NOASSERTION"), Relationship: "GENERATED_FROM", }, { - RefA: spdx.MakeDocElementID("", "JenaLib"), - RefB: spdx.MakeDocElementID("", "Package"), + RefA: common.MakeDocElementID("", "JenaLib"), + RefB: common.MakeDocElementID("", "Package"), Relationship: "CONTAINS", }, { - RefA: spdx.MakeDocElementID("", "File"), - RefB: spdx.MakeDocElementID("", "fromDoap-0"), + RefA: common.MakeDocElementID("", "File"), + RefB: common.MakeDocElementID("", "fromDoap-0"), Relationship: "GENERATED_FROM", }, }, diff --git a/json/parser.go b/json/parser.go index 387b5b06..5c9e6f4b 100644 --- a/json/parser.go +++ b/json/parser.go @@ -7,11 +7,11 @@ import ( "encoding/json" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) // Load2_2 takes in an io.Reader and returns an SPDX document. -func Load2_2(content io.Reader) (*spdx.Document2_2, error) { +func Load2_2(content io.Reader) (*v2_2.Document, error) { // convert io.Reader to a slice of bytes and call the parser buf := new(bytes.Buffer) _, err := buf.ReadFrom(content) @@ -19,7 +19,7 @@ func Load2_2(content io.Reader) (*spdx.Document2_2, error) { return nil, err } - var doc spdx.Document2_2 + var doc v2_2.Document err = json.Unmarshal(buf.Bytes(), &doc) if err != nil { return nil, err diff --git a/json/writer.go b/json/writer.go index c5980289..bcc00a72 100644 --- a/json/writer.go +++ b/json/writer.go @@ -6,11 +6,11 @@ import ( "encoding/json" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) // Save2_2 takes an SPDX Document (version 2.2) and an io.Writer, and writes the document to the writer in JSON format. -func Save2_2(doc *spdx.Document2_2, w io.Writer) error { +func Save2_2(doc *v2_2.Document, w io.Writer) error { buf, err := json.Marshal(doc) if err != nil { return err diff --git a/licensediff/licensediff.go b/licensediff/licensediff.go index 4b2f0acc..98da0e56 100644 --- a/licensediff/licensediff.go +++ b/licensediff/licensediff.go @@ -4,7 +4,8 @@ package licensediff import ( - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" ) // LicensePair is a result set where we are talking about two license strings, @@ -16,7 +17,7 @@ type LicensePair struct { // MakePairs2_1 essentially just consolidates all files and LicenseConcluded // strings into a single data structure. -func MakePairs2_1(p1 *spdx.Package2_1, p2 *spdx.Package2_1) (map[string]LicensePair, error) { +func MakePairs2_1(p1 *v2_1.Package, p2 *v2_1.Package) (map[string]LicensePair, error) { pairs := map[string]LicensePair{} // first, go through and add all files/licenses from p1 @@ -44,7 +45,7 @@ func MakePairs2_1(p1 *spdx.Package2_1, p2 *spdx.Package2_1) (map[string]LicenseP // 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) { +func MakePairs2_2(p1 *v2_2.Package, p2 *v2_2.Package) (map[string]LicensePair, error) { pairs := map[string]LicensePair{} // first, go through and add all files/licenses from p1 diff --git a/licensediff/licensediff_test.go b/licensediff/licensediff_test.go index 2142efc0..1992cce2 100644 --- a/licensediff/licensediff_test.go +++ b/licensediff/licensediff_test.go @@ -5,17 +5,19 @@ package licensediff import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== 2.1 License diff top-level function tests ===== func Test2_1DifferCanCreateDiffPairs(t *testing.T) { // create files to be used in diff // f1 will be identical in both - f1 := &spdx.File2_1{ + f1 := &v2_1.File{ FileName: "/project/file1.txt", - FileSPDXIdentifier: spdx.ElementID("File561"), - Checksums: []spdx.Checksum{{Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File561"), + Checksums: []common.Checksum{{Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", Algorithm: common.SHA1}}, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ "LicenseRef-We-will-ignore-LicenseInfoInFiles", @@ -24,10 +26,10 @@ func Test2_1DifferCanCreateDiffPairs(t *testing.T) { } // f2 will only appear in the first Package - f2 := &spdx.File2_1{ + f2 := &v2_1.File{ FileName: "/project/file2.txt", - FileSPDXIdentifier: spdx.ElementID("File562"), - Checksums: []spdx.Checksum{{Value: "066c5139bd9a43d15812ec1a1755b08ccf199824", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File562"), + Checksums: []common.Checksum{{Value: "066c5139bd9a43d15812ec1a1755b08ccf199824", Algorithm: common.SHA1}}, LicenseConcluded: "GPL-2.0-or-later", LicenseInfoInFiles: []string{ "NOASSERTION", @@ -36,10 +38,10 @@ func Test2_1DifferCanCreateDiffPairs(t *testing.T) { } // f3 will only appear in the second Package - f3 := &spdx.File2_1{ + f3 := &v2_1.File{ FileName: "/project/file3.txt", - FileSPDXIdentifier: spdx.ElementID("File563"), - Checksums: []spdx.Checksum{{Value: "bd0f4863b15fad2b79b35303af54fcb5baaf7c68", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File563"), + Checksums: []common.Checksum{{Value: "bd0f4863b15fad2b79b35303af54fcb5baaf7c68", Algorithm: common.SHA1}}, LicenseConcluded: "MPL-2.0", LicenseInfoInFiles: []string{ "NOASSERTION", @@ -49,20 +51,20 @@ func Test2_1DifferCanCreateDiffPairs(t *testing.T) { // f4_1 and f4_2 will appear in first and second, // with same name, same hash and different license - f4_1 := &spdx.File2_1{ + f4_1 := &v2_1.File{ FileName: "/project/file4.txt", - FileSPDXIdentifier: spdx.ElementID("File564"), - Checksums: []spdx.Checksum{{Value: "bc417a575ceae93435bcb7bfd382ac28cbdaa8b5", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File564"), + Checksums: []common.Checksum{{Value: "bc417a575ceae93435bcb7bfd382ac28cbdaa8b5", Algorithm: common.SHA1}}, LicenseConcluded: "MIT", LicenseInfoInFiles: []string{ "NOASSERTION", }, FileCopyrightText: "NOASSERTION", } - f4_2 := &spdx.File2_1{ + f4_2 := &v2_1.File{ FileName: "/project/file4.txt", - FileSPDXIdentifier: spdx.ElementID("File564"), - Checksums: []spdx.Checksum{{Value: "bc417a575ceae93435bcb7bfd382ac28cbdaa8b5", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File564"), + Checksums: []common.Checksum{{Value: "bc417a575ceae93435bcb7bfd382ac28cbdaa8b5", Algorithm: common.SHA1}}, LicenseConcluded: "Apache-2.0 AND MIT", LicenseInfoInFiles: []string{ "NOASSERTION", @@ -72,20 +74,20 @@ func Test2_1DifferCanCreateDiffPairs(t *testing.T) { // f5_1 and f5_2 will appear in first and second, // with same name, different hash and same license - f5_1 := &spdx.File2_1{ + f5_1 := &v2_1.File{ FileName: "/project/file5.txt", - FileSPDXIdentifier: spdx.ElementID("File565"), - Checksums: []spdx.Checksum{{Value: "ba226db943bbbf455da77afab6f16dbab156d000", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File565"), + Checksums: []common.Checksum{{Value: "ba226db943bbbf455da77afab6f16dbab156d000", Algorithm: common.SHA1}}, LicenseConcluded: "BSD-3-Clause", LicenseInfoInFiles: []string{ "NOASSERTION", }, FileCopyrightText: "NOASSERTION", } - f5_2 := &spdx.File2_1{ + f5_2 := &v2_1.File{ FileName: "/project/file5.txt", - FileSPDXIdentifier: spdx.ElementID("File565"), - Checksums: []spdx.Checksum{{Value: "b6e0ec7d085c5699b46f6f8d425413702652874d", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File565"), + Checksums: []common.Checksum{{Value: "b6e0ec7d085c5699b46f6f8d425413702652874d", Algorithm: common.SHA1}}, LicenseConcluded: "BSD-3-Clause", LicenseInfoInFiles: []string{ "NOASSERTION", @@ -95,20 +97,20 @@ func Test2_1DifferCanCreateDiffPairs(t *testing.T) { // f6_1 and f6_2 will appear in first and second, // with same name, different hash and different license - f6_1 := &spdx.File2_1{ + f6_1 := &v2_1.File{ FileName: "/project/file6.txt", - FileSPDXIdentifier: spdx.ElementID("File566"), - Checksums: []spdx.Checksum{{Value: "ba226db943bbbf455da77afab6f16dbab156d000", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File566"), + Checksums: []common.Checksum{{Value: "ba226db943bbbf455da77afab6f16dbab156d000", Algorithm: common.SHA1}}, LicenseConcluded: "CC0-1.0", LicenseInfoInFiles: []string{ "NOASSERTION", }, FileCopyrightText: "NOASSERTION", } - f6_2 := &spdx.File2_1{ + f6_2 := &v2_1.File{ FileName: "/project/file6.txt", - FileSPDXIdentifier: spdx.ElementID("File566"), - Checksums: []spdx.Checksum{{Value: "b6e0ec7d085c5699b46f6f8d425413702652874d", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File566"), + Checksums: []common.Checksum{{Value: "b6e0ec7d085c5699b46f6f8d425413702652874d", Algorithm: common.SHA1}}, LicenseConcluded: "Unlicense", LicenseInfoInFiles: []string{ "NOASSERTION", @@ -117,21 +119,21 @@ func Test2_1DifferCanCreateDiffPairs(t *testing.T) { } // create Packages - p1 := &spdx.Package2_1{ + p1 := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "NOASSERTION", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, // fake the verification code for present purposes - PackageVerificationCode: spdx.PackageVerificationCode{Value: "abc123abc123"}, + PackageVerificationCode: common.PackageVerificationCode{Value: "abc123abc123"}, PackageLicenseConcluded: "NOASSERTION", PackageLicenseInfoFromFiles: []string{ "NOASSERTION", }, PackageLicenseDeclared: "NOASSERTION", PackageCopyrightText: "NOASSERTION", - Files: []*spdx.File2_1{ + Files: []*v2_1.File{ f1, f2, f4_1, @@ -139,21 +141,21 @@ func Test2_1DifferCanCreateDiffPairs(t *testing.T) { f6_1, }, } - p2 := &spdx.Package2_1{ + p2 := &v2_1.Package{ PackageName: "p2", - PackageSPDXIdentifier: spdx.ElementID("p2"), + PackageSPDXIdentifier: common.ElementID("p2"), PackageDownloadLocation: "NOASSERTION", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, // fake the verification code for present purposes - PackageVerificationCode: spdx.PackageVerificationCode{Value: "def456def456"}, + PackageVerificationCode: common.PackageVerificationCode{Value: "def456def456"}, PackageLicenseConcluded: "NOASSERTION", PackageLicenseInfoFromFiles: []string{ "NOASSERTION", }, PackageLicenseDeclared: "NOASSERTION", PackageCopyrightText: "NOASSERTION", - Files: []*spdx.File2_1{ + Files: []*v2_1.File{ f1, f3, f4_2, @@ -251,10 +253,10 @@ func Test2_1DifferCanCreateDiffPairs(t *testing.T) { func Test2_1DifferCanCreateDiffStructuredResults(t *testing.T) { // create files to be used in diff // f1 will be identical in both - f1 := &spdx.File2_1{ + f1 := &v2_1.File{ FileName: "/project/file1.txt", - FileSPDXIdentifier: spdx.ElementID("File561"), - Checksums: []spdx.Checksum{{Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File561"), + Checksums: []common.Checksum{{Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", Algorithm: common.SHA1}}, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ "LicenseRef-We-will-ignore-LicenseInfoInFiles", @@ -263,10 +265,10 @@ func Test2_1DifferCanCreateDiffStructuredResults(t *testing.T) { } // f2 will only appear in the first Package - f2 := &spdx.File2_1{ + f2 := &v2_1.File{ FileName: "/project/file2.txt", - FileSPDXIdentifier: spdx.ElementID("File562"), - Checksums: []spdx.Checksum{{Value: "066c5139bd9a43d15812ec1a1755b08ccf199824", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File562"), + Checksums: []common.Checksum{{Value: "066c5139bd9a43d15812ec1a1755b08ccf199824", Algorithm: common.SHA1}}, LicenseConcluded: "GPL-2.0-or-later", LicenseInfoInFiles: []string{ "NOASSERTION", @@ -275,10 +277,10 @@ func Test2_1DifferCanCreateDiffStructuredResults(t *testing.T) { } // f3 will only appear in the second Package - f3 := &spdx.File2_1{ + f3 := &v2_1.File{ FileName: "/project/file3.txt", - FileSPDXIdentifier: spdx.ElementID("File563"), - Checksums: []spdx.Checksum{{Value: "bd0f4863b15fad2b79b35303af54fcb5baaf7c68", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File563"), + Checksums: []common.Checksum{{Value: "bd0f4863b15fad2b79b35303af54fcb5baaf7c68", Algorithm: common.SHA1}}, LicenseConcluded: "MPL-2.0", LicenseInfoInFiles: []string{ "NOASSERTION", @@ -288,20 +290,20 @@ func Test2_1DifferCanCreateDiffStructuredResults(t *testing.T) { // f4_1 and f4_2 will appear in first and second, // with same name, same hash and different license - f4_1 := &spdx.File2_1{ + f4_1 := &v2_1.File{ FileName: "/project/file4.txt", - FileSPDXIdentifier: spdx.ElementID("File564"), - Checksums: []spdx.Checksum{{Value: "bc417a575ceae93435bcb7bfd382ac28cbdaa8b5", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File564"), + Checksums: []common.Checksum{{Value: "bc417a575ceae93435bcb7bfd382ac28cbdaa8b5", Algorithm: common.SHA1}}, LicenseConcluded: "MIT", LicenseInfoInFiles: []string{ "NOASSERTION", }, FileCopyrightText: "NOASSERTION", } - f4_2 := &spdx.File2_1{ + f4_2 := &v2_1.File{ FileName: "/project/file4.txt", - FileSPDXIdentifier: spdx.ElementID("File564"), - Checksums: []spdx.Checksum{{Value: "bc417a575ceae93435bcb7bfd382ac28cbdaa8b5", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File564"), + Checksums: []common.Checksum{{Value: "bc417a575ceae93435bcb7bfd382ac28cbdaa8b5", Algorithm: common.SHA1}}, LicenseConcluded: "Apache-2.0 AND MIT", LicenseInfoInFiles: []string{ "NOASSERTION", @@ -311,20 +313,20 @@ func Test2_1DifferCanCreateDiffStructuredResults(t *testing.T) { // f5_1 and f5_2 will appear in first and second, // with same name, different hash and same license - f5_1 := &spdx.File2_1{ + f5_1 := &v2_1.File{ FileName: "/project/file5.txt", - FileSPDXIdentifier: spdx.ElementID("File565"), - Checksums: []spdx.Checksum{{Value: "ba226db943bbbf455da77afab6f16dbab156d000", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File565"), + Checksums: []common.Checksum{{Value: "ba226db943bbbf455da77afab6f16dbab156d000", Algorithm: common.SHA1}}, LicenseConcluded: "BSD-3-Clause", LicenseInfoInFiles: []string{ "NOASSERTION", }, FileCopyrightText: "NOASSERTION", } - f5_2 := &spdx.File2_1{ + f5_2 := &v2_1.File{ FileName: "/project/file5.txt", - FileSPDXIdentifier: spdx.ElementID("File565"), - Checksums: []spdx.Checksum{{Value: "b6e0ec7d085c5699b46f6f8d425413702652874d", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File565"), + Checksums: []common.Checksum{{Value: "b6e0ec7d085c5699b46f6f8d425413702652874d", Algorithm: common.SHA1}}, LicenseConcluded: "BSD-3-Clause", LicenseInfoInFiles: []string{ "NOASSERTION", @@ -334,20 +336,20 @@ func Test2_1DifferCanCreateDiffStructuredResults(t *testing.T) { // f6_1 and f6_2 will appear in first and second, // with same name, different hash and different license - f6_1 := &spdx.File2_1{ + f6_1 := &v2_1.File{ FileName: "/project/file6.txt", - FileSPDXIdentifier: spdx.ElementID("File566"), - Checksums: []spdx.Checksum{{Value: "ba226db943bbbf455da77afab6f16dbab156d000", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File566"), + Checksums: []common.Checksum{{Value: "ba226db943bbbf455da77afab6f16dbab156d000", Algorithm: common.SHA1}}, LicenseConcluded: "CC0-1.0", LicenseInfoInFiles: []string{ "NOASSERTION", }, FileCopyrightText: "NOASSERTION", } - f6_2 := &spdx.File2_1{ + f6_2 := &v2_1.File{ FileName: "/project/file6.txt", - FileSPDXIdentifier: spdx.ElementID("File566"), - Checksums: []spdx.Checksum{{Value: "b6e0ec7d085c5699b46f6f8d425413702652874d", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File566"), + Checksums: []common.Checksum{{Value: "b6e0ec7d085c5699b46f6f8d425413702652874d", Algorithm: common.SHA1}}, LicenseConcluded: "Unlicense", LicenseInfoInFiles: []string{ "NOASSERTION", @@ -356,21 +358,21 @@ func Test2_1DifferCanCreateDiffStructuredResults(t *testing.T) { } // create Packages - p1 := &spdx.Package2_1{ + p1 := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "NOASSERTION", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, // fake the verification code for present purposes - PackageVerificationCode: spdx.PackageVerificationCode{Value: "abc123abc123"}, + PackageVerificationCode: common.PackageVerificationCode{Value: "abc123abc123"}, PackageLicenseConcluded: "NOASSERTION", PackageLicenseInfoFromFiles: []string{ "NOASSERTION", }, PackageLicenseDeclared: "NOASSERTION", PackageCopyrightText: "NOASSERTION", - Files: []*spdx.File2_1{ + Files: []*v2_1.File{ f1, f2, f4_1, @@ -378,21 +380,21 @@ func Test2_1DifferCanCreateDiffStructuredResults(t *testing.T) { f6_1, }, } - p2 := &spdx.Package2_1{ + p2 := &v2_1.Package{ PackageName: "p2", - PackageSPDXIdentifier: spdx.ElementID("p2"), + PackageSPDXIdentifier: common.ElementID("p2"), PackageDownloadLocation: "NOASSERTION", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, // fake the verification code for present purposes - PackageVerificationCode: spdx.PackageVerificationCode{Value: "def456def456"}, + PackageVerificationCode: common.PackageVerificationCode{Value: "def456def456"}, PackageLicenseConcluded: "NOASSERTION", PackageLicenseInfoFromFiles: []string{ "NOASSERTION", }, PackageLicenseDeclared: "NOASSERTION", PackageCopyrightText: "NOASSERTION", - Files: []*spdx.File2_1{ + Files: []*v2_1.File{ f1, f3, f4_2, @@ -498,11 +500,11 @@ func Test2_1DifferCanCreateDiffStructuredResults(t *testing.T) { func Test2_2DifferCanCreateDiffPairs(t *testing.T) { // create files to be used in diff // f1 will be identical in both - f1 := &spdx.File2_2{ + f1 := &v2_2.File{ FileName: "/project/file1.txt", - FileSPDXIdentifier: spdx.ElementID("File561"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File561"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -514,11 +516,11 @@ func Test2_2DifferCanCreateDiffPairs(t *testing.T) { } // f2 will only appear in the first Package - f2 := &spdx.File2_2{ + f2 := &v2_2.File{ FileName: "/project/file2.txt", - FileSPDXIdentifier: spdx.ElementID("File562"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File562"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -530,11 +532,11 @@ func Test2_2DifferCanCreateDiffPairs(t *testing.T) { } // f3 will only appear in the second Package - f3 := &spdx.File2_2{ + f3 := &v2_2.File{ FileName: "/project/file3.txt", - FileSPDXIdentifier: spdx.ElementID("File563"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File563"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -547,11 +549,11 @@ func Test2_2DifferCanCreateDiffPairs(t *testing.T) { // f4_1 and f4_2 will appear in first and second, // with same name, same hash and different license - f4_1 := &spdx.File2_2{ + f4_1 := &v2_2.File{ FileName: "/project/file4.txt", - FileSPDXIdentifier: spdx.ElementID("File564"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File564"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -561,11 +563,11 @@ func Test2_2DifferCanCreateDiffPairs(t *testing.T) { }, FileCopyrightText: "NOASSERTION", } - f4_2 := &spdx.File2_2{ + f4_2 := &v2_2.File{ FileName: "/project/file4.txt", - FileSPDXIdentifier: spdx.ElementID("File564"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File564"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -578,11 +580,11 @@ func Test2_2DifferCanCreateDiffPairs(t *testing.T) { // f5_1 and f5_2 will appear in first and second, // with same name, different hash and same license - f5_1 := &spdx.File2_2{ + f5_1 := &v2_2.File{ FileName: "/project/file5.txt", - FileSPDXIdentifier: spdx.ElementID("File565"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File565"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -592,11 +594,11 @@ func Test2_2DifferCanCreateDiffPairs(t *testing.T) { }, FileCopyrightText: "NOASSERTION", } - f5_2 := &spdx.File2_2{ + f5_2 := &v2_2.File{ FileName: "/project/file5.txt", - FileSPDXIdentifier: spdx.ElementID("File565"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File565"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -609,11 +611,11 @@ func Test2_2DifferCanCreateDiffPairs(t *testing.T) { // f6_1 and f6_2 will appear in first and second, // with same name, different hash and different license - f6_1 := &spdx.File2_2{ + f6_1 := &v2_2.File{ FileName: "/project/file6.txt", - FileSPDXIdentifier: spdx.ElementID("File566"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File566"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -623,11 +625,11 @@ func Test2_2DifferCanCreateDiffPairs(t *testing.T) { }, FileCopyrightText: "NOASSERTION", } - f6_2 := &spdx.File2_2{ + f6_2 := &v2_2.File{ FileName: "/project/file6.txt", - FileSPDXIdentifier: spdx.ElementID("File566"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File566"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -639,21 +641,21 @@ func Test2_2DifferCanCreateDiffPairs(t *testing.T) { } // create Packages - p1 := &spdx.Package2_2{ + p1 := &v2_2.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "NOASSERTION", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, // fake the verification code for present purposes - PackageVerificationCode: spdx.PackageVerificationCode{Value: "abc123abc123"}, + PackageVerificationCode: common.PackageVerificationCode{Value: "abc123abc123"}, PackageLicenseConcluded: "NOASSERTION", PackageLicenseInfoFromFiles: []string{ "NOASSERTION", }, PackageLicenseDeclared: "NOASSERTION", PackageCopyrightText: "NOASSERTION", - Files: []*spdx.File2_2{ + Files: []*v2_2.File{ f1, f2, f4_1, @@ -661,21 +663,21 @@ func Test2_2DifferCanCreateDiffPairs(t *testing.T) { f6_1, }, } - p2 := &spdx.Package2_2{ + p2 := &v2_2.Package{ PackageName: "p2", - PackageSPDXIdentifier: spdx.ElementID("p2"), + PackageSPDXIdentifier: common.ElementID("p2"), PackageDownloadLocation: "NOASSERTION", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, // fake the verification code for present purposes - PackageVerificationCode: spdx.PackageVerificationCode{Value: "def456def456"}, + PackageVerificationCode: common.PackageVerificationCode{Value: "def456def456"}, PackageLicenseConcluded: "NOASSERTION", PackageLicenseInfoFromFiles: []string{ "NOASSERTION", }, PackageLicenseDeclared: "NOASSERTION", PackageCopyrightText: "NOASSERTION", - Files: []*spdx.File2_2{ + Files: []*v2_2.File{ f1, f3, f4_2, @@ -773,11 +775,11 @@ func Test2_2DifferCanCreateDiffPairs(t *testing.T) { func Test2_2DifferCanCreateDiffStructuredResults(t *testing.T) { // create files to be used in diff // f1 will be identical in both - f1 := &spdx.File2_2{ + f1 := &v2_2.File{ FileName: "/project/file1.txt", - FileSPDXIdentifier: spdx.ElementID("File561"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File561"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -789,11 +791,11 @@ func Test2_2DifferCanCreateDiffStructuredResults(t *testing.T) { } // f2 will only appear in the first Package - f2 := &spdx.File2_2{ + f2 := &v2_2.File{ FileName: "/project/file2.txt", - FileSPDXIdentifier: spdx.ElementID("File562"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File562"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -805,11 +807,11 @@ func Test2_2DifferCanCreateDiffStructuredResults(t *testing.T) { } // f3 will only appear in the second Package - f3 := &spdx.File2_2{ + f3 := &v2_2.File{ FileName: "/project/file3.txt", - FileSPDXIdentifier: spdx.ElementID("File563"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File563"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -822,11 +824,11 @@ func Test2_2DifferCanCreateDiffStructuredResults(t *testing.T) { // f4_1 and f4_2 will appear in first and second, // with same name, same hash and different license - f4_1 := &spdx.File2_2{ + f4_1 := &v2_2.File{ FileName: "/project/file4.txt", - FileSPDXIdentifier: spdx.ElementID("File564"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File564"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -836,11 +838,11 @@ func Test2_2DifferCanCreateDiffStructuredResults(t *testing.T) { }, FileCopyrightText: "NOASSERTION", } - f4_2 := &spdx.File2_2{ + f4_2 := &v2_2.File{ FileName: "/project/file4.txt", - FileSPDXIdentifier: spdx.ElementID("File564"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File564"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -853,20 +855,20 @@ func Test2_2DifferCanCreateDiffStructuredResults(t *testing.T) { // f5_1 and f5_2 will appear in first and second, // with same name, different hash and same license - f5_1 := &spdx.File2_2{ + f5_1 := &v2_2.File{ FileName: "/project/file5.txt", - FileSPDXIdentifier: spdx.ElementID("File565"), + FileSPDXIdentifier: common.ElementID("File565"), LicenseConcluded: "BSD-3-Clause", LicenseInfoInFiles: []string{ "NOASSERTION", }, FileCopyrightText: "NOASSERTION", } - f5_2 := &spdx.File2_2{ + f5_2 := &v2_2.File{ FileName: "/project/file5.txt", - FileSPDXIdentifier: spdx.ElementID("File565"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File565"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -880,11 +882,11 @@ func Test2_2DifferCanCreateDiffStructuredResults(t *testing.T) { // f6_1 and f6_2 will appear in first and second, // with same name, different hash and different license - f6_1 := &spdx.File2_2{ + f6_1 := &v2_2.File{ FileName: "/project/file6.txt", - FileSPDXIdentifier: spdx.ElementID("File566"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File566"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -894,11 +896,11 @@ func Test2_2DifferCanCreateDiffStructuredResults(t *testing.T) { }, FileCopyrightText: "NOASSERTION", } - f6_2 := &spdx.File2_2{ + f6_2 := &v2_2.File{ FileName: "/project/file6.txt", - FileSPDXIdentifier: spdx.ElementID("File566"), - Checksums: []spdx.Checksum{{ - Algorithm: spdx.SHA1, + FileSPDXIdentifier: common.ElementID("File566"), + Checksums: []common.Checksum{{ + Algorithm: common.SHA1, Value: "6c92dc8bc462b6889d9b1c0bc16c54d19a2cbdd3", }, }, @@ -910,21 +912,21 @@ func Test2_2DifferCanCreateDiffStructuredResults(t *testing.T) { } // create Packages - p1 := &spdx.Package2_2{ + p1 := &v2_2.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "NOASSERTION", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, // fake the verification code for present purposes - PackageVerificationCode: spdx.PackageVerificationCode{Value: "abc123abc123"}, + PackageVerificationCode: common.PackageVerificationCode{Value: "abc123abc123"}, PackageLicenseConcluded: "NOASSERTION", PackageLicenseInfoFromFiles: []string{ "NOASSERTION", }, PackageLicenseDeclared: "NOASSERTION", PackageCopyrightText: "NOASSERTION", - Files: []*spdx.File2_2{ + Files: []*v2_2.File{ f1, f2, f4_1, @@ -932,21 +934,21 @@ func Test2_2DifferCanCreateDiffStructuredResults(t *testing.T) { f6_1, }, } - p2 := &spdx.Package2_2{ + p2 := &v2_2.Package{ PackageName: "p2", - PackageSPDXIdentifier: spdx.ElementID("p2"), + PackageSPDXIdentifier: common.ElementID("p2"), PackageDownloadLocation: "NOASSERTION", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, // fake the verification code for present purposes - PackageVerificationCode: spdx.PackageVerificationCode{Value: "def456def456"}, + PackageVerificationCode: common.PackageVerificationCode{Value: "def456def456"}, PackageLicenseConcluded: "NOASSERTION", PackageLicenseInfoFromFiles: []string{ "NOASSERTION", }, PackageLicenseDeclared: "NOASSERTION", PackageCopyrightText: "NOASSERTION", - Files: []*spdx.File2_2{ + Files: []*v2_2.File{ f1, f3, f4_2, diff --git a/rdfloader/parser2v2/license_utils.go b/rdfloader/parser2v2/license_utils.go index 0a823efe..41e8870d 100644 --- a/rdfloader/parser2v2/license_utils.go +++ b/rdfloader/parser2v2/license_utils.go @@ -4,9 +4,10 @@ package parser2v2 import ( "fmt" - gordfParser "github.com/spdx/gordf/rdfloader/parser" - "github.com/spdx/tools-golang/spdx" "strings" + + gordfParser "github.com/spdx/gordf/rdfloader/parser" + "github.com/spdx/tools-golang/spdx/common" ) /* util methods for licenses and checksums below:*/ @@ -26,7 +27,7 @@ func getLicenseStringFromURI(uri string) string { // returns the checksum algorithm and it's value // In the newer versions, these two strings will be bound to a single checksum struct // whose pointer will be returned. -func (parser *rdfParser2_2) getChecksumFromNode(checksumNode *gordfParser.Node) (algorithm spdx.ChecksumAlgorithm, value string, err error) { +func (parser *rdfParser2_2) getChecksumFromNode(checksumNode *gordfParser.Node) (algorithm common.ChecksumAlgorithm, value string, err error) { var checksumValue, checksumAlgorithm string for _, checksumTriple := range parser.nodeToTriples(checksumNode) { switch checksumTriple.Predicate.ID { @@ -46,7 +47,7 @@ func (parser *rdfParser2_2) getChecksumFromNode(checksumNode *gordfParser.Node) return } } - return spdx.ChecksumAlgorithm(checksumAlgorithm), checksumValue, nil + return common.ChecksumAlgorithm(checksumAlgorithm), checksumValue, nil } func getAlgorithmFromURI(algorithmURI string) (checksumAlgorithm string, err error) { diff --git a/rdfloader/parser2v2/parse_annotation.go b/rdfloader/parser2v2/parse_annotation.go index 18e4533d..a5801b0b 100644 --- a/rdfloader/parser2v2/parse_annotation.go +++ b/rdfloader/parser2v2/parse_annotation.go @@ -5,15 +5,16 @@ package parser2v2 import ( "errors" "fmt" + gordfParser "github.com/spdx/gordf/rdfloader/parser" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) // creates a new instance of annotation and sets the annotation attributes // associated with the given node. // The newly created annotation is appended to the doc. func (parser *rdfParser2_2) parseAnnotationFromNode(node *gordfParser.Node) (err error) { - ann := &spdx.Annotation2_2{} + ann := &v2_2.Annotation{} for _, subTriple := range parser.nodeToTriples(node) { switch subTriple.Predicate.ID { case SPDX_ANNOTATOR: @@ -41,19 +42,19 @@ func (parser *rdfParser2_2) parseAnnotationFromNode(node *gordfParser.Node) (err return setAnnotationToParser(parser, ann) } -func setAnnotationToParser(parser *rdfParser2_2, annotation *spdx.Annotation2_2) error { +func setAnnotationToParser(parser *rdfParser2_2, annotation *v2_2.Annotation) error { if parser.doc == nil { return errors.New("uninitialized spdx document") } if parser.doc.Annotations == nil { - parser.doc.Annotations = []*spdx.Annotation2_2{} + parser.doc.Annotations = []*v2_2.Annotation{} } parser.doc.Annotations = append(parser.doc.Annotations, annotation) return nil } // annotator is of type [Person|Organization|Tool]:String -func setAnnotatorFromString(annotatorString string, ann *spdx.Annotation2_2) error { +func setAnnotatorFromString(annotatorString string, ann *v2_2.Annotation) error { subkey, subvalue, err := ExtractSubs(annotatorString, ":") if err != nil { return err @@ -67,7 +68,7 @@ func setAnnotatorFromString(annotatorString string, ann *spdx.Annotation2_2) err } // it can be NS_SPDX+annotationType_[review|other] -func setAnnotationType(annType string, ann *spdx.Annotation2_2) error { +func setAnnotationType(annType string, ann *v2_2.Annotation) error { switch annType { case SPDX_ANNOTATION_TYPE_OTHER: ann.AnnotationType = "OTHER" diff --git a/rdfloader/parser2v2/parse_annotation_test.go b/rdfloader/parser2v2/parse_annotation_test.go index 0226d856..114fc5de 100644 --- a/rdfloader/parser2v2/parse_annotation_test.go +++ b/rdfloader/parser2v2/parse_annotation_test.go @@ -3,13 +3,14 @@ package parser2v2 import ( - "github.com/spdx/tools-golang/spdx" "testing" + + "github.com/spdx/tools-golang/spdx/v2_2" ) func Test_setAnnotatorFromString(t *testing.T) { // TestCase 1: Empty String must raise an error - ann := &spdx.Annotation2_2{} + ann := &v2_2.Annotation{} input := "" err := setAnnotatorFromString(input, ann) if err == nil { @@ -17,7 +18,7 @@ func Test_setAnnotatorFromString(t *testing.T) { } // TestCase 2: Invalid annotator type - ann = &spdx.Annotation2_2{} + ann = &v2_2.Annotation{} input = "Company: some_company" err = setAnnotatorFromString(input, ann) if err == nil { @@ -25,7 +26,7 @@ func Test_setAnnotatorFromString(t *testing.T) { } // TestCase 3: Valid annotator - ann = &spdx.Annotation2_2{} + ann = &v2_2.Annotation{} input = "Person: Rishabh" err = setAnnotatorFromString(input, ann) if err != nil { @@ -40,7 +41,7 @@ func Test_setAnnotatorFromString(t *testing.T) { } func Test_setAnnotationType(t *testing.T) { - ann := &spdx.Annotation2_2{} + ann := &v2_2.Annotation{} // TestCase 1: invalid input (empty annotationType) err := setAnnotationType("", ann) if err == nil { @@ -76,7 +77,7 @@ func Test_setAnnotationToParser(t *testing.T) { // TestCase 1: doc is nil (must raise an error) parser, _ := parserFromBodyContent(``) parser.doc = nil - err := setAnnotationToParser(parser, &spdx.Annotation2_2{}) + err := setAnnotationToParser(parser, &v2_2.Annotation{}) if err == nil { t.Errorf("empty doc should've raised an error") } @@ -85,7 +86,7 @@ func Test_setAnnotationToParser(t *testing.T) { // list and append the input to it. parser, _ = parserFromBodyContent(``) parser.doc.Annotations = nil - err = setAnnotationToParser(parser, &spdx.Annotation2_2{}) + err = setAnnotationToParser(parser, &v2_2.Annotation{}) if err != nil { t.Errorf("unexpected error: %v", err) } diff --git a/rdfloader/parser2v2/parse_creation_info.go b/rdfloader/parser2v2/parse_creation_info.go index dc4da77e..b58149d0 100644 --- a/rdfloader/parser2v2/parse_creation_info.go +++ b/rdfloader/parser2v2/parse_creation_info.go @@ -4,12 +4,14 @@ package parser2v2 import ( "fmt" + gordfParser "github.com/spdx/gordf/rdfloader/parser" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // Cardinality: Mandatory, one. -func (parser *rdfParser2_2) parseCreationInfoFromNode(ci *spdx.CreationInfo2_2, node *gordfParser.Node) error { +func (parser *rdfParser2_2) parseCreationInfoFromNode(ci *v2_2.CreationInfo, node *gordfParser.Node) error { for _, triple := range parser.nodeToTriples(node) { switch triple.Predicate.ID { case SPDX_LICENSE_LIST_VERSION: // 2.7 @@ -35,13 +37,13 @@ func (parser *rdfParser2_2) parseCreationInfoFromNode(ci *spdx.CreationInfo2_2, return nil } -func setCreator(creatorStr string, ci *spdx.CreationInfo2_2) error { +func setCreator(creatorStr string, ci *v2_2.CreationInfo) error { entityType, entity, err := ExtractSubs(creatorStr, ":") if err != nil { return fmt.Errorf("error setting creator of a creation info: %s", err) } - creator := spdx.Creator{Creator: entity} + creator := common.Creator{Creator: entity} switch entityType { case "Person", "Organization", "Tool": diff --git a/rdfloader/parser2v2/parse_creation_info_test.go b/rdfloader/parser2v2/parse_creation_info_test.go index 415d18ed..81fceaee 100644 --- a/rdfloader/parser2v2/parse_creation_info_test.go +++ b/rdfloader/parser2v2/parse_creation_info_test.go @@ -3,28 +3,29 @@ package parser2v2 import ( - "github.com/spdx/tools-golang/spdx" "testing" + + "github.com/spdx/tools-golang/spdx/v2_2" ) func Test_setCreator(t *testing.T) { // TestCase 1: invalid creator (empty) input := "" - err := setCreator(input, &spdx.CreationInfo2_2{}) + err := setCreator(input, &v2_2.CreationInfo{}) if err == nil { t.Errorf("shoud've raised an error due to invalid input") } // TestCase 2: invalid entity type input = "Company: some company" - err = setCreator(input, &spdx.CreationInfo2_2{}) + err = setCreator(input, &v2_2.CreationInfo{}) if err == nil { t.Errorf("shoud've raised an error due to unknown entity type") } // TestCase 3: valid input input = "Person: Jane Doe" - ci := &spdx.CreationInfo2_2{} + ci := &v2_2.CreationInfo{} err = setCreator(input, ci) if err != nil { t.Errorf("error parsing a valid input: %v", err) @@ -48,7 +49,7 @@ func Test_rdfParser2_2_parseCreationInfoFromNode(t *testing.T) { `) ciNode := parser.gordfParserObj.Triples[0].Subject - err := parser.parseCreationInfoFromNode(&spdx.CreationInfo2_2{}, ciNode) + err := parser.parseCreationInfoFromNode(&v2_2.CreationInfo{}, ciNode) if err == nil { t.Errorf("invalid creator must raise an error") } @@ -65,7 +66,7 @@ func Test_rdfParser2_2_parseCreationInfoFromNode(t *testing.T) { `) ciNode = parser.gordfParserObj.Triples[0].Subject - err = parser.parseCreationInfoFromNode(&spdx.CreationInfo2_2{}, ciNode) + err = parser.parseCreationInfoFromNode(&v2_2.CreationInfo{}, ciNode) if err == nil { t.Errorf("unknown predicate must raise an error") } @@ -80,7 +81,7 @@ func Test_rdfParser2_2_parseCreationInfoFromNode(t *testing.T) { `) ciNode = parser.gordfParserObj.Triples[0].Subject - ci := &spdx.CreationInfo2_2{} + ci := &v2_2.CreationInfo{} err = parser.parseCreationInfoFromNode(ci, ciNode) if err != nil { t.Errorf("unexpected error: %v", err) diff --git a/rdfloader/parser2v2/parse_file.go b/rdfloader/parser2v2/parse_file.go index a149712d..e807667e 100644 --- a/rdfloader/parser2v2/parse_file.go +++ b/rdfloader/parser2v2/parse_file.go @@ -7,12 +7,13 @@ import ( "strings" gordfParser "github.com/spdx/gordf/rdfloader/parser" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // returns a file instance and the error if any encountered. -func (parser *rdfParser2_2) getFileFromNode(fileNode *gordfParser.Node) (file *spdx.File2_2, err error) { - file = &spdx.File2_2{} +func (parser *rdfParser2_2) getFileFromNode(fileNode *gordfParser.Node) (file *v2_2.File, err error) { + file = &v2_2.File{} currState := parser.cache[fileNode.ID] if currState == nil { @@ -23,7 +24,7 @@ func (parser *rdfParser2_2) getFileFromNode(fileNode *gordfParser.Node) (file *s } } else if currState.Color == GREY { // we have already started parsing this file node and we needn't parse it again. - return currState.object.(*spdx.File2_2), nil + return currState.object.(*v2_2.File), nil } // setting color to grey to indicate that we've started parsing this node. @@ -86,7 +87,7 @@ func (parser *rdfParser2_2) getFileFromNode(fileNode *gordfParser.Node) (file *s // deprecated artifactOf (see sections 4.9, 4.10, 4.11) case SPDX_ARTIFACT_OF: // cardinality: min 0 - var artifactOf *spdx.ArtifactOfProject2_2 + var artifactOf *v2_2.ArtifactOfProject artifactOf, err = parser.getArtifactFromNode(subTriple.Object) file.ArtifactOfProjects = append(file.ArtifactOfProjects, artifactOf) case RDFS_COMMENT: // 4.12 @@ -125,17 +126,17 @@ func (parser *rdfParser2_2) getFileFromNode(fileNode *gordfParser.Node) (file *s return file, nil } -func (parser *rdfParser2_2) setFileChecksumFromNode(file *spdx.File2_2, checksumNode *gordfParser.Node) error { +func (parser *rdfParser2_2) setFileChecksumFromNode(file *v2_2.File, checksumNode *gordfParser.Node) error { checksumAlgorithm, checksumValue, err := parser.getChecksumFromNode(checksumNode) if err != nil { return fmt.Errorf("error parsing checksumNode of a file: %v", err) } if file.Checksums == nil { - file.Checksums = []spdx.Checksum{} + file.Checksums = []common.Checksum{} } switch checksumAlgorithm { - case spdx.MD5, spdx.SHA1, spdx.SHA256: - file.Checksums = append(file.Checksums, spdx.Checksum{Algorithm: checksumAlgorithm, Value: checksumValue}) + case common.MD5, common.SHA1, common.SHA256: + file.Checksums = append(file.Checksums, common.Checksum{Algorithm: checksumAlgorithm, Value: checksumValue}) case "": return fmt.Errorf("empty checksum algorithm and value") default: @@ -144,8 +145,8 @@ func (parser *rdfParser2_2) setFileChecksumFromNode(file *spdx.File2_2, checksum return nil } -func (parser *rdfParser2_2) getArtifactFromNode(node *gordfParser.Node) (*spdx.ArtifactOfProject2_2, error) { - artifactOf := &spdx.ArtifactOfProject2_2{} +func (parser *rdfParser2_2) getArtifactFromNode(node *gordfParser.Node) (*v2_2.ArtifactOfProject, error) { + artifactOf := &v2_2.ArtifactOfProject{} // setting artifactOfProjectURI attribute (which is optional) if node.NodeType == gordfParser.IRI { artifactOf.URI = node.ID @@ -186,7 +187,7 @@ func (parser *rdfParser2_2) setUnpackagedFiles() { } } -func setFileIdentifier(idURI string, file *spdx.File2_2) (err error) { +func setFileIdentifier(idURI string, file *v2_2.File) (err error) { idURI = strings.TrimSpace(idURI) uriFragment := getLastPartOfURI(idURI) file.FileSPDXIdentifier, err = ExtractElementID(uriFragment) diff --git a/rdfloader/parser2v2/parse_file_test.go b/rdfloader/parser2v2/parse_file_test.go index 8c5ea0df..25093517 100644 --- a/rdfloader/parser2v2/parse_file_test.go +++ b/rdfloader/parser2v2/parse_file_test.go @@ -10,7 +10,8 @@ import ( gordfParser "github.com/spdx/gordf/rdfloader/parser" rdfloader2 "github.com/spdx/gordf/rdfloader/xmlreader" gordfWriter "github.com/spdx/gordf/rdfwriter" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // content is the tags within the rdf:RDF tag @@ -143,9 +144,9 @@ func Test_rdfParser2_2_setUnpackagedFiles(t *testing.T) { // unpackaged files are the files which are not associated with any package // file associated with a package sets parser.assocWithPackage[fileID] to true. rdfParser, _ := parserFromBodyContent(``) - file1 := &spdx.File2_2{FileSPDXIdentifier: spdx.ElementID("file1")} - file2 := &spdx.File2_2{FileSPDXIdentifier: spdx.ElementID("file2")} - file3 := &spdx.File2_2{FileSPDXIdentifier: spdx.ElementID("file3")} + file1 := &v2_2.File{FileSPDXIdentifier: common.ElementID("file1")} + file2 := &v2_2.File{FileSPDXIdentifier: common.ElementID("file2")} + file3 := &v2_2.File{FileSPDXIdentifier: common.ElementID("file3")} // setting files to the document as if it were to be set when it was parsed using triples. rdfParser.files[file1.FileSPDXIdentifier] = file1 @@ -174,7 +175,7 @@ func Test_rdfParser2_2_setUnpackagedFiles(t *testing.T) { } func Test_setFileIdentifier(t *testing.T) { - file := &spdx.File2_2{} + file := &v2_2.File{} // TestCase 1: valid example err := setFileIdentifier("http://spdx.org/documents/spdx-toolsv2.1.7-SNAPSHOT#SPDXRef-129", file) @@ -201,7 +202,7 @@ func Test_rdfParser2_2_setFileChecksumFromNode(t *testing.T) { `) checksumNode := gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_CHECKSUM_CAPITALIZED)[0].Subject - file := &spdx.File2_2{} + file := &v2_2.File{} err := parser.setFileChecksumFromNode(file, checksumNode) if err != nil { t.Errorf("error parsing a valid checksum node") @@ -209,15 +210,15 @@ func Test_rdfParser2_2_setFileChecksumFromNode(t *testing.T) { checksumValue := "d2356e0fe1c0b85285d83c6b2ad51b5f" for _, checksum := range file.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != "" { t.Errorf("incorrectly set sha1, should've been empty") } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "" { t.Errorf("incorrectly set sha256, should've been empty") } - case spdx.MD5: + case common.MD5: if checksum.Value != checksumValue { t.Errorf("wrong checksum value for md5. Expected: %s, found: %s", checksumValue, checksum.Value) } @@ -232,22 +233,22 @@ func Test_rdfParser2_2_setFileChecksumFromNode(t *testing.T) { `) checksumNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_CHECKSUM_CAPITALIZED)[0].Subject - file = &spdx.File2_2{} + file = &v2_2.File{} err = parser.setFileChecksumFromNode(file, checksumNode) if err != nil { t.Errorf("error parsing a valid checksum node") } for _, checksum := range file.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != checksumValue { t.Errorf("wrong checksum value for sha1. Expected: %s, found: %s", checksumValue, checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != "" { t.Errorf("incorrectly set sha256, should've been empty") } - case spdx.MD5: + case common.MD5: if checksum.Value != checksumValue { t.Errorf("incorrectly set md5, should've been empty") } @@ -262,22 +263,22 @@ func Test_rdfParser2_2_setFileChecksumFromNode(t *testing.T) { `) checksumNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_CHECKSUM_CAPITALIZED)[0].Subject - file = &spdx.File2_2{} + file = &v2_2.File{} err = parser.setFileChecksumFromNode(file, checksumNode) if err != nil { t.Errorf("error parsing a valid checksum node") } for _, checksum := range file.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != checksumValue { t.Errorf("incorrectly set sha1, should've been empty") } - case spdx.SHA256: + case common.SHA256: if checksum.Value != checksumValue { t.Errorf("wrong checksum value for sha256. Expected: %s, found: %s", checksumValue, checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != checksumValue { t.Errorf("incorrectly set md5, should've been empty") } @@ -291,7 +292,7 @@ func Test_rdfParser2_2_setFileChecksumFromNode(t *testing.T) { `) checksumNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_CHECKSUM_CAPITALIZED)[0].Subject - file = &spdx.File2_2{} + file = &v2_2.File{} err = parser.setFileChecksumFromNode(file, checksumNode) if err == nil { t.Errorf("should've raised an error parsing an invalid checksum node") @@ -305,7 +306,7 @@ func Test_rdfParser2_2_setFileChecksumFromNode(t *testing.T) { `) checksumNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_CHECKSUM_CAPITALIZED)[0].Subject - file = &spdx.File2_2{} + file = &v2_2.File{} err = parser.setFileChecksumFromNode(file, checksumNode) if err == nil { t.Errorf("should've raised an error parsing an invalid checksum node") @@ -319,7 +320,7 @@ func Test_rdfParser2_2_setFileChecksumFromNode(t *testing.T) { `) checksumNode = gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_CHECKSUM_CAPITALIZED)[0].Subject - file = &spdx.File2_2{} + file = &v2_2.File{} err = parser.setFileChecksumFromNode(file, checksumNode) if err == nil { t.Errorf("should've raised an error parsing an invalid checksum algorithm for a file") @@ -484,7 +485,7 @@ func Test_rdfParser2_2_getFileFromNode(t *testing.T) { } parser, _ = parserFromBodyContent(strings.Join(fileDefinitions, "")) - var file *spdx.File2_2 + var file *v2_2.File packageTypeTriples := gordfWriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_PACKAGE) for _, typeTriple := range packageTypeTriples { pkg, err := parser.getPackageFromNode(typeTriple.Subject) @@ -602,7 +603,7 @@ func Test_rdfParser2_2_getFileFromNode(t *testing.T) { for _, checksum := range file.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != expectedChecksum { t.Errorf("expected %s, found %s", expectedChecksum, checksum.Value) } diff --git a/rdfloader/parser2v2/parse_license.go b/rdfloader/parser2v2/parse_license.go index 4b4ad46b..71a1e4a2 100644 --- a/rdfloader/parser2v2/parse_license.go +++ b/rdfloader/parser2v2/parse_license.go @@ -5,9 +5,10 @@ package parser2v2 import ( "errors" "fmt" + "strings" + gordfParser "github.com/spdx/gordf/rdfloader/parser" "github.com/spdx/gordf/rdfwriter" - "strings" ) // AnyLicense is a baseClass for all the licenses @@ -37,7 +38,7 @@ func (parser *rdfParser2_2) getAnyLicenseFromNode(node *gordfParser.Node) (AnyLi parser.cache[node.ID].Color = GREY // setting state color to black when we're done parsing this node. - defer func(){parser.cache[node.ID].Color = BLACK}() + defer func() { parser.cache[node.ID].Color = BLACK }() associatedTriples := rdfwriter.FilterTriples(parser.gordfParserObj.Triples, &node.ID, nil, nil) if len(associatedTriples) == 0 { diff --git a/rdfloader/parser2v2/parse_license_test.go b/rdfloader/parser2v2/parse_license_test.go index b519195b..e2c684dc 100644 --- a/rdfloader/parser2v2/parse_license_test.go +++ b/rdfloader/parser2v2/parse_license_test.go @@ -3,10 +3,11 @@ package parser2v2 import ( - gordfParser "github.com/spdx/gordf/rdfloader/parser" "reflect" "sort" "testing" + + gordfParser "github.com/spdx/gordf/rdfloader/parser" ) func Test_rdfParser2_2_getAnyLicenseFromNode(t *testing.T) { diff --git a/rdfloader/parser2v2/parse_other_license_info.go b/rdfloader/parser2v2/parse_other_license_info.go index e7d1367a..97dcf0c5 100644 --- a/rdfloader/parser2v2/parse_other_license_info.go +++ b/rdfloader/parser2v2/parse_other_license_info.go @@ -4,9 +4,10 @@ package parser2v2 import ( "fmt" + gordfParser "github.com/spdx/gordf/rdfloader/parser" "github.com/spdx/gordf/rdfwriter" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) func (parser *rdfParser2_2) getExtractedLicensingInfoFromNode(node *gordfParser.Node) (lic ExtractedLicensingInfo, err error) { @@ -27,7 +28,7 @@ func (parser *rdfParser2_2) getExtractedLicensingInfoFromNode(node *gordfParser. return lic, nil } -func (parser *rdfParser2_2) extractedLicenseToOtherLicense(extLicense ExtractedLicensingInfo) (othLic spdx.OtherLicense2_2) { +func (parser *rdfParser2_2) extractedLicenseToOtherLicense(extLicense ExtractedLicensingInfo) (othLic v2_2.OtherLicense) { othLic.LicenseIdentifier = extLicense.licenseID othLic.ExtractedText = extLicense.extractedText othLic.LicenseComment = extLicense.comment diff --git a/rdfloader/parser2v2/parse_other_license_info_test.go b/rdfloader/parser2v2/parse_other_license_info_test.go index e606d504..cd7ad321 100644 --- a/rdfloader/parser2v2/parse_other_license_info_test.go +++ b/rdfloader/parser2v2/parse_other_license_info_test.go @@ -3,9 +3,10 @@ package parser2v2 import ( - gordfParser "github.com/spdx/gordf/rdfloader/parser" "reflect" "testing" + + gordfParser "github.com/spdx/gordf/rdfloader/parser" ) func Test_rdfParser2_2_getExtractedLicensingInfoFromNode(t *testing.T) { diff --git a/rdfloader/parser2v2/parse_package.go b/rdfloader/parser2v2/parse_package.go index 41ccab30..eff2e0fe 100644 --- a/rdfloader/parser2v2/parse_package.go +++ b/rdfloader/parser2v2/parse_package.go @@ -7,11 +7,12 @@ import ( "strings" gordfParser "github.com/spdx/gordf/rdfloader/parser" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) -func (parser *rdfParser2_2) getPackageFromNode(packageNode *gordfParser.Node) (pkg *spdx.Package2_2, err error) { - pkg = &spdx.Package2_2{} // new package which will be returned +func (parser *rdfParser2_2) getPackageFromNode(packageNode *gordfParser.Node) (pkg *v2_2.Package, err error) { + pkg = &v2_2.Package{} // new package which will be returned currState := parser.cache[packageNode.ID] if currState == nil { @@ -23,7 +24,7 @@ func (parser *rdfParser2_2) getPackageFromNode(packageNode *gordfParser.Node) (p } } else if currState.Color == GREY { // we have already started parsing this package node and we needn't parse it again. - return currState.object.(*spdx.Package2_2), nil + return currState.object.(*v2_2.Package), nil } // setting color of the state to grey to indicate that we've started to @@ -166,8 +167,8 @@ func (parser *rdfParser2_2) getPackageFromNode(packageNode *gordfParser.Node) (p } // parses externalReference found in the package by the associated triple. -func (parser *rdfParser2_2) getPackageExternalRef(node *gordfParser.Node) (externalDocRef *spdx.PackageExternalReference2_2, err error) { - externalDocRef = &spdx.PackageExternalReference2_2{} +func (parser *rdfParser2_2) getPackageExternalRef(node *gordfParser.Node) (externalDocRef *v2_2.PackageExternalReference, err error) { + externalDocRef = &v2_2.PackageExternalReference{} for _, triple := range parser.nodeToTriples(node) { switch triple.Predicate.ID { case SPDX_REFERENCE_CATEGORY: @@ -205,7 +206,7 @@ func (parser *rdfParser2_2) getPackageExternalRef(node *gordfParser.Node) (exter return } -func (parser *rdfParser2_2) setPackageVerificationCode(pkg *spdx.Package2_2, node *gordfParser.Node) error { +func (parser *rdfParser2_2) setPackageVerificationCode(pkg *v2_2.Package, node *gordfParser.Node) error { for _, subTriple := range parser.nodeToTriples(node) { switch subTriple.Predicate.ID { case SPDX_PACKAGE_VERIFICATION_CODE_VALUE: @@ -226,9 +227,9 @@ func (parser *rdfParser2_2) setPackageVerificationCode(pkg *spdx.Package2_2, nod // appends the file to the package and also sets the assocWithPackage for the // file to indicate the file is associated with a package -func (parser *rdfParser2_2) setFileToPackage(pkg *spdx.Package2_2, file *spdx.File2_2) { +func (parser *rdfParser2_2) setFileToPackage(pkg *v2_2.Package, file *v2_2.File) { if pkg.Files == nil { - pkg.Files = []*spdx.File2_2{} + pkg.Files = []*v2_2.File{} } pkg.Files = append(pkg.Files, file) parser.assocWithPackage[file.FileSPDXIdentifier] = true @@ -237,9 +238,9 @@ func (parser *rdfParser2_2) setFileToPackage(pkg *spdx.Package2_2, file *spdx.Fi // given a supplierObject, sets the PackageSupplier attribute of the pkg. // Args: // value: [NOASSERTION | [Person | Organization]: string] -func setPackageSupplier(pkg *spdx.Package2_2, value string) error { +func setPackageSupplier(pkg *v2_2.Package, value string) error { value = strings.TrimSpace(value) - supplier := &spdx.Supplier{} + supplier := &common.Supplier{} if strings.ToUpper(value) == "NOASSERTION" { supplier.Supplier = "NOASSERTION" pkg.PackageSupplier = supplier @@ -266,9 +267,9 @@ func setPackageSupplier(pkg *spdx.Package2_2, value string) error { // given a OriginatorObject, sets the PackageOriginator attribute of the pkg. // Args: // value: [NOASSERTION | [Person | Organization]: string] -func setPackageOriginator(pkg *spdx.Package2_2, value string) error { +func setPackageOriginator(pkg *v2_2.Package, value string) error { value = strings.TrimSpace(value) - originator := &spdx.Originator{} + originator := &common.Originator{} if strings.ToUpper(value) == "NOASSERTION" { originator.Originator = "NOASSERTION" pkg.PackageOriginator = originator @@ -293,7 +294,7 @@ func setPackageOriginator(pkg *spdx.Package2_2, value string) error { } // validates the uri and sets the location if it is valid -func setDocumentLocationFromURI(pkg *spdx.Package2_2, locationURI string) error { +func setDocumentLocationFromURI(pkg *v2_2.Package, locationURI string) error { switch locationURI { case SPDX_NOASSERTION_CAPS, SPDX_NOASSERTION_SMALL: pkg.PackageDownloadLocation = "NOASSERTION" @@ -310,23 +311,23 @@ func setDocumentLocationFromURI(pkg *spdx.Package2_2, locationURI string) error // sets the FilesAnalyzed attribute to the given package // boolValue is a string of type "true" or "false" -func setFilesAnalyzed(pkg *spdx.Package2_2, boolValue string) (err error) { +func setFilesAnalyzed(pkg *v2_2.Package, boolValue string) (err error) { pkg.IsFilesAnalyzedTagPresent = true pkg.FilesAnalyzed, err = boolFromString(boolValue) return err } -func (parser *rdfParser2_2) setPackageChecksum(pkg *spdx.Package2_2, node *gordfParser.Node) error { +func (parser *rdfParser2_2) setPackageChecksum(pkg *v2_2.Package, node *gordfParser.Node) error { checksumAlgorithm, checksumValue, err := parser.getChecksumFromNode(node) if err != nil { return fmt.Errorf("error getting checksum algorithm and value from %v", node) } if pkg.PackageChecksums == nil { - pkg.PackageChecksums = make([]spdx.Checksum, 0, 1) + pkg.PackageChecksums = make([]common.Checksum, 0, 1) } switch checksumAlgorithm { - case spdx.MD5, spdx.SHA1, spdx.SHA256: - pkg.PackageChecksums = append(pkg.PackageChecksums, spdx.Checksum{Algorithm: checksumAlgorithm, Value: checksumValue}) + case common.MD5, common.SHA1, common.SHA256: + pkg.PackageChecksums = append(pkg.PackageChecksums, common.Checksum{Algorithm: checksumAlgorithm, Value: checksumValue}) default: return fmt.Errorf("unknown checksumAlgorithm %s while parsing a package", checksumAlgorithm) } diff --git a/rdfloader/parser2v2/parse_package_test.go b/rdfloader/parser2v2/parse_package_test.go index c1bc7ed6..0e01dbe8 100644 --- a/rdfloader/parser2v2/parse_package_test.go +++ b/rdfloader/parser2v2/parse_package_test.go @@ -7,14 +7,15 @@ import ( "testing" gordfParser "github.com/spdx/gordf/rdfloader/parser" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) func Test_setPackageSupplier(t *testing.T) { var err error // TestCase 1: no assertion must set PackageSupplierNOASSERTION field to true - pkg := &spdx.Package2_2{} + pkg := &v2_2.Package{} err = setPackageSupplier(pkg, "NOASSERTION") if err != nil { t.Fatalf("unexpected error: %v", err) @@ -25,7 +26,7 @@ func Test_setPackageSupplier(t *testing.T) { // TestCase 2: lower-case noassertion must also set the // PackageSupplierNOASSERTION to true. - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} err = setPackageSupplier(pkg, "noassertion") if err != nil { t.Fatalf("unexpected error: %v", err) @@ -35,7 +36,7 @@ func Test_setPackageSupplier(t *testing.T) { } // TestCase 3: invalid input without colon separator. must raise an error - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} input := "string without colon separator" err = setPackageSupplier(pkg, input) if err == nil { @@ -43,7 +44,7 @@ func Test_setPackageSupplier(t *testing.T) { } // TestCase 4: Valid Person - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} personName := "Rishabh Bhatnagar" input = "Person: " + personName err = setPackageSupplier(pkg, input) @@ -55,7 +56,7 @@ func Test_setPackageSupplier(t *testing.T) { } // TestCase 5: Valid Organization - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} orgName := "SPDX" input = "Organization: " + orgName err = setPackageSupplier(pkg, input) @@ -67,7 +68,7 @@ func Test_setPackageSupplier(t *testing.T) { } // TestCase 6: Invalid EntityType - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} input = "InvalidEntity: entity" err = setPackageSupplier(pkg, input) if err == nil { @@ -79,7 +80,7 @@ func Test_setPackageOriginator(t *testing.T) { var err error // TestCase 1: no assertion must set PackageSupplierNOASSERTION field to true - pkg := &spdx.Package2_2{} + pkg := &v2_2.Package{} err = setPackageOriginator(pkg, "NOASSERTION") if err != nil { t.Fatalf("unexpected error: %v", err) @@ -90,7 +91,7 @@ func Test_setPackageOriginator(t *testing.T) { // TestCase 2: lower-case noassertion must also set the // PackageOriginatorNOASSERTION to true. - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} err = setPackageOriginator(pkg, "noassertion") if err != nil { t.Fatalf("unexpected error: %v", err) @@ -100,7 +101,7 @@ func Test_setPackageOriginator(t *testing.T) { } // TestCase 3: invalid input without colon separator. must raise an error - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} input := "string without colon separator" err = setPackageOriginator(pkg, input) if err == nil { @@ -108,7 +109,7 @@ func Test_setPackageOriginator(t *testing.T) { } // TestCase 4: Valid Person - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} personName := "Rishabh Bhatnagar" input = "Person: " + personName err = setPackageOriginator(pkg, input) @@ -120,7 +121,7 @@ func Test_setPackageOriginator(t *testing.T) { } // TestCase 5: Valid Organization - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} orgName := "SPDX" input = "Organization: " + orgName err = setPackageOriginator(pkg, input) @@ -132,7 +133,7 @@ func Test_setPackageOriginator(t *testing.T) { } // TestCase 6: Invalid EntityType - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} input = "InvalidEntity: entity" err = setPackageOriginator(pkg, input) if err == nil { @@ -143,19 +144,19 @@ func Test_setPackageOriginator(t *testing.T) { func Test_rdfParser2_2_setPackageVerificationCode(t *testing.T) { var parser *rdfParser2_2 var node *gordfParser.Node - var pkg *spdx.Package2_2 + var pkg *v2_2.Package var err error // TestCase 1: invalid predicate must raise an error parser, _ = parserFromBodyContent(` - + cbceb8b5689b75a584efe35587b5d41bd48820ce ./package.spdx - + `) node = parser.gordfParserObj.Triples[0].Subject - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} err = parser.setPackageVerificationCode(pkg, node) if err == nil { t.Errorf("expected an error due to invalid predicate, got ") @@ -163,13 +164,13 @@ func Test_rdfParser2_2_setPackageVerificationCode(t *testing.T) { // TestCase 2: valid input parser, _ = parserFromBodyContent(` - + cbceb8b5689b75a584efe35587b5d41bd48820ce ./package.spdx - + `) node = parser.gordfParserObj.Triples[0].Subject - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} err = parser.setPackageVerificationCode(pkg, node) if err != nil { t.Errorf("unexpected error: %v", err) @@ -185,7 +186,7 @@ func Test_rdfParser2_2_setPackageVerificationCode(t *testing.T) { } func Test_rdfParser2_2_getPackageExternalRef(t *testing.T) { - var extRef *spdx.PackageExternalReference2_2 + var extRef *v2_2.PackageExternalReference var err error var parser *rdfParser2_2 var node *gordfParser.Node @@ -239,7 +240,7 @@ func Test_rdfParser2_2_getPackageExternalRef(t *testing.T) { if err != nil { t.Fatalf("unexpected error parsing a valid example: %v", err) } - expectedExtRef := &spdx.PackageExternalReference2_2{ + expectedExtRef := &v2_2.PackageExternalReference{ Locator: "cpe:2.3:a:pivotal_software:spring_framework:4.1.0:*:*:*:*:*:*:*", RefType: "http://spdx.org/rdf/references/cpe23Type", Category: "SECURITY", @@ -265,7 +266,7 @@ func Test_rdfParser2_2_getPackageExternalRef(t *testing.T) { if err != nil { t.Fatalf("unexpected error parsing a valid example: %v", err) } - expectedExtRef = &spdx.PackageExternalReference2_2{ + expectedExtRef = &v2_2.PackageExternalReference{ Locator: "cpe:2.3:a:pivotal_software:spring_framework:4.1.0:*:*:*:*:*:*:*", RefType: "http://spdx.org/rdf/references/cpe23Type", Category: "PACKAGE-MANAGER", @@ -291,7 +292,7 @@ func Test_rdfParser2_2_getPackageExternalRef(t *testing.T) { if err != nil { t.Fatalf("unexpected error parsing a valid example: %v", err) } - expectedExtRef = &spdx.PackageExternalReference2_2{ + expectedExtRef = &v2_2.PackageExternalReference{ Locator: "cpe:2.3:a:pivotal_software:spring_framework:4.1.0:*:*:*:*:*:*:*", RefType: "http://spdx.org/rdf/references/cpe23Type", Category: "OTHER", @@ -503,10 +504,10 @@ func Test_rdfParser2_2_getPackageFromNode(t *testing.T) { true - + cbceb8b5689b75a584efe35587b5d41bd48820ce ./package.spdx - + @@ -564,14 +565,14 @@ func Test_rdfParser2_2_getPackageFromNode(t *testing.T) { } func Test_rdfParser2_2_setFileToPackage(t *testing.T) { - var pkg *spdx.Package2_2 - var file *spdx.File2_2 + var pkg *v2_2.Package + var file *v2_2.File var parser *rdfParser2_2 // TestCase 1: setting to a nil files attribute shouldn't panic. parser, _ = parserFromBodyContent(``) - pkg = &spdx.Package2_2{} - file = &spdx.File2_2{} + pkg = &v2_2.Package{} + file = &v2_2.File{} parser.setFileToPackage(pkg, file) if len(pkg.Files) != 1 { t.Errorf("expected given package to have one file after setting, got %d", len(pkg.Files)) @@ -584,7 +585,7 @@ func Test_rdfParser2_2_setFileToPackage(t *testing.T) { func Test_rdfParser2_2_setPackageChecksum(t *testing.T) { var parser *rdfParser2_2 var node *gordfParser.Node - var pkg *spdx.Package2_2 + var pkg *v2_2.Package var expectedChecksumValue string var err error @@ -595,7 +596,7 @@ func Test_rdfParser2_2_setPackageChecksum(t *testing.T) { `) - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setPackageChecksum(pkg, node) if err == nil { @@ -609,7 +610,7 @@ func Test_rdfParser2_2_setPackageChecksum(t *testing.T) { `) - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setPackageChecksum(pkg, node) if err == nil { @@ -623,7 +624,7 @@ func Test_rdfParser2_2_setPackageChecksum(t *testing.T) { `) - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setPackageChecksum(pkg, node) if err != nil { @@ -633,7 +634,7 @@ func Test_rdfParser2_2_setPackageChecksum(t *testing.T) { for _, checksum := range pkg.PackageChecksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != expectedChecksumValue { t.Errorf("expected %v, got: %v", expectedChecksumValue, checksum.Value) } @@ -647,7 +648,7 @@ func Test_rdfParser2_2_setPackageChecksum(t *testing.T) { `) - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setPackageChecksum(pkg, node) if err != nil { @@ -656,7 +657,7 @@ func Test_rdfParser2_2_setPackageChecksum(t *testing.T) { expectedChecksumValue = "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" for _, checksum := range pkg.PackageChecksums { switch checksum.Algorithm { - case spdx.SHA256: + case common.SHA256: if checksum.Value != expectedChecksumValue { t.Errorf("expected %v, got: %v", expectedChecksumValue, checksum.Value) } @@ -670,7 +671,7 @@ func Test_rdfParser2_2_setPackageChecksum(t *testing.T) { `) - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setPackageChecksum(pkg, node) if err != nil { @@ -679,7 +680,7 @@ func Test_rdfParser2_2_setPackageChecksum(t *testing.T) { expectedChecksumValue = "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" for _, checksum := range pkg.PackageChecksums { switch checksum.Algorithm { - case spdx.MD5: + case common.MD5: if checksum.Value != expectedChecksumValue { t.Errorf("expected %v, got: %v", expectedChecksumValue, checksum.Value) } @@ -688,14 +689,14 @@ func Test_rdfParser2_2_setPackageChecksum(t *testing.T) { } func Test_setDocumentLocationFromURI(t *testing.T) { - var pkg *spdx.Package2_2 + var pkg *v2_2.Package var expectedDocumentLocation, gotDocumentLocation string var inputURI string var err error // TestCase 1: NOASSERTION inputURI = SPDX_NOASSERTION_SMALL - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} err = setDocumentLocationFromURI(pkg, inputURI) if err != nil { t.Fatalf("unexpected error: %v", err) @@ -708,7 +709,7 @@ func Test_setDocumentLocationFromURI(t *testing.T) { // TestCase 2: NONE inputURI = SPDX_NONE_CAPS - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} err = setDocumentLocationFromURI(pkg, inputURI) if err != nil { t.Fatalf("unexpected error: %v", err) @@ -721,7 +722,7 @@ func Test_setDocumentLocationFromURI(t *testing.T) { // TestCase 3: valid uri inputURI = "https://www.gnu.org/software/texinfo/" - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} err = setDocumentLocationFromURI(pkg, inputURI) if err != nil { t.Fatalf("unexpected error: %v", err) @@ -734,7 +735,7 @@ func Test_setDocumentLocationFromURI(t *testing.T) { // TestCase 3: invalid uri inputURI = " " - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} err = setDocumentLocationFromURI(pkg, inputURI) if err == nil { t.Fatalf("expected an error due to invalid uri, got %v", err) @@ -742,18 +743,18 @@ func Test_setDocumentLocationFromURI(t *testing.T) { } func Test_setFilesAnalyzed(t *testing.T) { - var pkg *spdx.Package2_2 + var pkg *v2_2.Package var err error // TestCase 1: not a valid bool value: - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} err = setFilesAnalyzed(pkg, "no") if err == nil { t.Errorf("expected an error due to invalid bool input, got %v", err) } // TestCase 2: valid input - pkg = &spdx.Package2_2{} + pkg = &v2_2.Package{} err = setFilesAnalyzed(pkg, "true") if err != nil { t.Fatalf("unexpected error: %v", err) diff --git a/rdfloader/parser2v2/parse_relationship.go b/rdfloader/parser2v2/parse_relationship.go index c4e85403..49f10257 100644 --- a/rdfloader/parser2v2/parse_relationship.go +++ b/rdfloader/parser2v2/parse_relationship.go @@ -4,10 +4,12 @@ package parser2v2 import ( "fmt" + "strings" + gordfParser "github.com/spdx/gordf/rdfloader/parser" "github.com/spdx/gordf/rdfwriter" - "github.com/spdx/tools-golang/spdx" - "strings" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // parsing the relationship that exists in the rdf document. @@ -15,7 +17,7 @@ import ( // parsing the relationship appends the relationship to the current document's // Relationships Slice. func (parser *rdfParser2_2) parseRelationship(triple *gordfParser.Triple) (err error) { - reln := spdx.Relationship2_2{} + reln := v2_2.Relationship{} reln.RefA, err = getReferenceFromURI(triple.Subject.ID) if err != nil { @@ -40,7 +42,7 @@ func (parser *rdfParser2_2) parseRelationship(triple *gordfParser.Triple) (err e parser.cache[triple.Object.ID].Color = GREY // setting state color to black to indicate when we're done parsing this node. - defer func(){parser.cache[triple.Object.ID].Color = BLACK}(); + defer func() { parser.cache[triple.Object.ID].Color = BLACK }() for _, subTriple := range parser.nodeToTriples(triple.Object) { switch subTriple.Predicate.ID { @@ -85,7 +87,7 @@ func (parser *rdfParser2_2) parseRelationship(triple *gordfParser.Triple) (err e return nil } -func (parser *rdfParser2_2) parseRelatedElementFromTriple(reln *spdx.Relationship2_2, triple *gordfParser.Triple) error { +func (parser *rdfParser2_2) parseRelatedElementFromTriple(reln *v2_2.Relationship, triple *gordfParser.Triple) error { // iterate over relatedElement Type and check which SpdxElement it is. var err error switch triple.Object.ID { @@ -94,7 +96,7 @@ func (parser *rdfParser2_2) parseRelatedElementFromTriple(reln *spdx.Relationshi if err != nil { return fmt.Errorf("error setting a file: %v", err) } - reln.RefB = spdx.DocElementID{ + reln.RefB = common.DocElementID{ DocumentRefID: "", ElementRefID: file.FileSPDXIdentifier, } @@ -104,7 +106,7 @@ func (parser *rdfParser2_2) parseRelatedElementFromTriple(reln *spdx.Relationshi if err != nil { return fmt.Errorf("error setting a package inside a relationship: %v", err) } - reln.RefB = spdx.DocElementID{ + reln.RefB = common.DocElementID{ DocumentRefID: "", ElementRefID: pkg.PackageSPDXIdentifier, } @@ -123,13 +125,13 @@ func (parser *rdfParser2_2) parseRelatedElementFromTriple(reln *spdx.Relationshi } // references like RefA and RefB of any relationship -func getReferenceFromURI(uri string) (spdx.DocElementID, error) { +func getReferenceFromURI(uri string) (common.DocElementID, error) { fragment := getLastPartOfURI(uri) switch strings.ToLower(strings.TrimSpace(fragment)) { case "noassertion", "none": - return spdx.DocElementID{ + return common.DocElementID{ DocumentRefID: "", - ElementRefID: spdx.ElementID(strings.ToUpper(fragment)), + ElementRefID: common.ElementID(strings.ToUpper(fragment)), }, nil } return ExtractDocElementID(fragment) diff --git a/rdfloader/parser2v2/parse_relationship_test.go b/rdfloader/parser2v2/parse_relationship_test.go index 14f4c129..fd66d148 100644 --- a/rdfloader/parser2v2/parse_relationship_test.go +++ b/rdfloader/parser2v2/parse_relationship_test.go @@ -3,10 +3,12 @@ package parser2v2 import ( - "github.com/spdx/gordf/rdfwriter" - "github.com/spdx/tools-golang/spdx" "reflect" "testing" + + "github.com/spdx/gordf/rdfwriter" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) func Test_getReferenceFromURI(t *testing.T) { @@ -81,20 +83,20 @@ func Test_rdfParser2_2_parseRelatedElementFromTriple(t *testing.T) { `) - reln := &spdx.Relationship2_2{} + reln := &v2_2.Relationship{} triple := rdfwriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_PACKAGE)[0] err := parser.parseRelatedElementFromTriple(reln, triple) if err != nil { t.Errorf("error parsing a valid example") } - expectedRefA := spdx.DocElementID{ + expectedRefA := common.DocElementID{ DocumentRefID: "", ElementRefID: "", } if !reflect.DeepEqual(expectedRefA, reln.RefA) { t.Errorf("expected %+v, found %+v", expectedRefA, reln.RefA) } - expectedRefB := spdx.DocElementID{ + expectedRefB := common.DocElementID{ DocumentRefID: "", ElementRefID: "Saxon", } @@ -110,7 +112,7 @@ func Test_rdfParser2_2_parseRelatedElementFromTriple(t *testing.T) { `) - reln = &spdx.Relationship2_2{} + reln = &v2_2.Relationship{} triple = rdfwriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_PACKAGE)[0] err = parser.parseRelatedElementFromTriple(reln, triple) if err == nil { @@ -125,20 +127,20 @@ func Test_rdfParser2_2_parseRelatedElementFromTriple(t *testing.T) { `) - reln = &spdx.Relationship2_2{} + reln = &v2_2.Relationship{} triple = rdfwriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_FILE)[0] err = parser.parseRelatedElementFromTriple(reln, triple) if err != nil { t.Errorf("error parsing a valid example") } - expectedRefA = spdx.DocElementID{ + expectedRefA = common.DocElementID{ DocumentRefID: "", ElementRefID: "", } if !reflect.DeepEqual(expectedRefA, reln.RefA) { t.Errorf("expected %+v, found %+v", expectedRefA, reln.RefA) } - expectedRefB = spdx.DocElementID{ + expectedRefB = common.DocElementID{ DocumentRefID: "", ElementRefID: "Saxon", } @@ -154,7 +156,7 @@ func Test_rdfParser2_2_parseRelatedElementFromTriple(t *testing.T) { `) - reln = &spdx.Relationship2_2{} + reln = &v2_2.Relationship{} triple = rdfwriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_FILE)[0] err = parser.parseRelatedElementFromTriple(reln, triple) if err == nil { @@ -169,20 +171,20 @@ func Test_rdfParser2_2_parseRelatedElementFromTriple(t *testing.T) { `) - reln = &spdx.Relationship2_2{} + reln = &v2_2.Relationship{} triple = rdfwriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_SPDX_ELEMENT)[0] err = parser.parseRelatedElementFromTriple(reln, triple) if err != nil { t.Errorf("error parsing a valid example") } - expectedRefA = spdx.DocElementID{ + expectedRefA = common.DocElementID{ DocumentRefID: "", ElementRefID: "", } if !reflect.DeepEqual(expectedRefA, reln.RefA) { t.Errorf("expected %+v, found %+v", expectedRefA, reln.RefA) } - expectedRefB = spdx.DocElementID{ + expectedRefB = common.DocElementID{ DocumentRefID: "", ElementRefID: "File", } @@ -198,7 +200,7 @@ func Test_rdfParser2_2_parseRelatedElementFromTriple(t *testing.T) { `) - reln = &spdx.Relationship2_2{} + reln = &v2_2.Relationship{} triple = rdfwriter.FilterTriples(parser.gordfParserObj.Triples, nil, &RDF_TYPE, &SPDX_SPDX_ELEMENT)[0] err = parser.parseRelatedElementFromTriple(reln, triple) if err == nil { @@ -374,14 +376,14 @@ func Test_rdfParser2_2_parseRelationship(t *testing.T) { if reln.Relationship != expectedRelnType { t.Errorf("expected %s, found %s", expectedRelnType, reln.Relationship) } - expectedRefA := spdx.DocElementID{ + expectedRefA := common.DocElementID{ DocumentRefID: "", ElementRefID: "File", } if !reflect.DeepEqual(expectedRefA, reln.RefA) { t.Errorf("expected %+v, found %+v", expectedRefA, reln.RefA) } - expectedRefB := spdx.DocElementID{ + expectedRefB := common.DocElementID{ DocumentRefID: "", ElementRefID: "Saxon", } diff --git a/rdfloader/parser2v2/parse_review.go b/rdfloader/parser2v2/parse_review.go index 437042d5..40c87d33 100644 --- a/rdfloader/parser2v2/parse_review.go +++ b/rdfloader/parser2v2/parse_review.go @@ -4,12 +4,13 @@ package parser2v2 import ( "fmt" + gordfParser "github.com/spdx/gordf/rdfloader/parser" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) func (parser *rdfParser2_2) setReviewFromNode(reviewedNode *gordfParser.Node) error { - review := spdx.Review2_2{} + review := v2_2.Review{} for _, triple := range parser.nodeToTriples(reviewedNode) { switch triple.Predicate.ID { case RDF_TYPE: diff --git a/rdfloader/parser2v2/parse_snippet_info.go b/rdfloader/parser2v2/parse_snippet_info.go index a09d6716..5e80944d 100644 --- a/rdfloader/parser2v2/parse_snippet_info.go +++ b/rdfloader/parser2v2/parse_snippet_info.go @@ -4,16 +4,18 @@ package parser2v2 import ( "fmt" + "strconv" + gordfParser "github.com/spdx/gordf/rdfloader/parser" "github.com/spdx/gordf/rdfwriter" - "github.com/spdx/tools-golang/spdx" - "strconv" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // Snippet Information // Cardinality: Optional, Many -func (parser *rdfParser2_2) getSnippetInformationFromNode2_2(node *gordfParser.Node) (si *spdx.Snippet2_2, err error) { - si = &spdx.Snippet2_2{} +func (parser *rdfParser2_2) getSnippetInformationFromNode2_2(node *gordfParser.Node) (si *v2_2.Snippet, err error) { + si = &v2_2.Snippet{} err = setSnippetID(node.ID, si) if err != nil { @@ -72,14 +74,14 @@ func (parser *rdfParser2_2) getSnippetInformationFromNode2_2(node *gordfParser.N } // given is the id of the file, sets the snippet to the file in parser. -func (parser *rdfParser2_2) setSnippetToFileWithID(snippet *spdx.Snippet2_2, fileID spdx.ElementID) error { +func (parser *rdfParser2_2) setSnippetToFileWithID(snippet *v2_2.Snippet, fileID common.ElementID) error { if parser.files[fileID] == nil { return fmt.Errorf("snippet refers to an undefined file with ID: %s", fileID) } // initializing snippet of the files if it is not defined already if parser.files[fileID].Snippets == nil { - parser.files[fileID].Snippets = map[spdx.ElementID]*spdx.Snippet2_2{} + parser.files[fileID].Snippets = map[common.ElementID]*v2_2.Snippet{} } // setting the snippet to the file. @@ -88,7 +90,7 @@ func (parser *rdfParser2_2) setSnippetToFileWithID(snippet *spdx.Snippet2_2, fil return nil } -func (parser *rdfParser2_2) setSnippetRangeFromNode(node *gordfParser.Node, si *spdx.Snippet2_2) error { +func (parser *rdfParser2_2) setSnippetRangeFromNode(node *gordfParser.Node, si *v2_2.Snippet) error { // for a range object, we can have only 3 associated triples: // node -> RDF_TYPE -> Object // node -> startPointer -> Object @@ -132,9 +134,9 @@ func (parser *rdfParser2_2) setSnippetRangeFromNode(node *gordfParser.Node, si * return fmt.Errorf("start and end range type doesn't match") } - si.Ranges = []spdx.SnippetRange{{ - StartPointer: spdx.SnippetRangePointer{FileSPDXIdentifier: si.SnippetFromFileSPDXIdentifier}, - EndPointer: spdx.SnippetRangePointer{FileSPDXIdentifier: si.SnippetFromFileSPDXIdentifier}, + si.Ranges = []common.SnippetRange{{ + StartPointer: common.SnippetRangePointer{FileSPDXIdentifier: si.SnippetFromFileSPDXIdentifier}, + EndPointer: common.SnippetRangePointer{FileSPDXIdentifier: si.SnippetFromFileSPDXIdentifier}, }} if startRangeType == LINE_RANGE { @@ -147,7 +149,7 @@ func (parser *rdfParser2_2) setSnippetRangeFromNode(node *gordfParser.Node, si * return nil } -func (parser *rdfParser2_2) getPointerFromNode(node *gordfParser.Node, si *spdx.Snippet2_2) (rt RangeType, number int, err error) { +func (parser *rdfParser2_2) getPointerFromNode(node *gordfParser.Node, si *v2_2.Snippet) (rt RangeType, number int, err error) { for _, triple := range parser.nodeToTriples(node) { switch triple.Predicate.ID { case RDF_TYPE: @@ -172,7 +174,7 @@ func (parser *rdfParser2_2) getPointerFromNode(node *gordfParser.Node, si *spdx. return } -func (parser *rdfParser2_2) parseRangeReference(node *gordfParser.Node, snippet *spdx.Snippet2_2) error { +func (parser *rdfParser2_2) parseRangeReference(node *gordfParser.Node, snippet *v2_2.Snippet) error { // reference is supposed to be either a resource reference to an already // defined or a new file. Unfortunately, I didn't find field where this can be set in the tools-golang data model. // todo: set this reference to the snippet @@ -187,7 +189,7 @@ func (parser *rdfParser2_2) parseRangeReference(node *gordfParser.Node, snippet return nil } -func setSnippetID(uri string, si *spdx.Snippet2_2) (err error) { +func setSnippetID(uri string, si *v2_2.Snippet) (err error) { fragment := getLastPartOfURI(uri) si.SnippetSPDXIdentifier, err = ExtractElementID(fragment) if err != nil { diff --git a/rdfloader/parser2v2/parse_snippet_info_test.go b/rdfloader/parser2v2/parse_snippet_info_test.go index 47e999e0..df0bb70e 100644 --- a/rdfloader/parser2v2/parse_snippet_info_test.go +++ b/rdfloader/parser2v2/parse_snippet_info_test.go @@ -3,9 +3,11 @@ package parser2v2 import ( - gordfParser "github.com/spdx/gordf/rdfloader/parser" - "github.com/spdx/tools-golang/spdx" "testing" + + gordfParser "github.com/spdx/gordf/rdfloader/parser" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) func Test_rdfParser2_2_getSnippetInformationFromTriple2_2(t *testing.T) { @@ -129,13 +131,13 @@ func Test_rdfParser2_2_getSnippetInformationFromTriple2_2(t *testing.T) { func Test_setSnippetID(t *testing.T) { // TestCase 1: invalid input (empty) - err := setSnippetID("", &spdx.Snippet2_2{}) + err := setSnippetID("", &v2_2.Snippet{}) if err == nil { t.Errorf("should've raised an error for empty input") } // TestCase 2: valid input - si := &spdx.Snippet2_2{} + si := &v2_2.Snippet{} err = setSnippetID("http://spdx.org/spdxdocs/spdx-example#SPDXRef-Snippet", si) if err != nil { t.Errorf("unexpected error: %v", err) @@ -149,10 +151,10 @@ func Test_rdfParser2_2_parseRangeReference(t *testing.T) { var err error var node *gordfParser.Node var parser *rdfParser2_2 - var si *spdx.Snippet2_2 + var si *v2_2.Snippet // TestCase 1: ResourceLiteral node without a new file shouldn't raise any error. - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} parser, _ = parserFromBodyContent(``) node = &gordfParser.Node{ NodeType: gordfParser.RESOURCELITERAL, @@ -164,7 +166,7 @@ func Test_rdfParser2_2_parseRangeReference(t *testing.T) { } // TestCase 2: invalid file in the reference should raise an error - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} parser, _ = parserFromBodyContent(` test file @@ -177,7 +179,7 @@ func Test_rdfParser2_2_parseRangeReference(t *testing.T) { } // TestCase 3: A valid reference must set the file to the files map of the parser. - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} parser, _ = parserFromBodyContent(` test file @@ -196,7 +198,7 @@ func Test_rdfParser2_2_parseRangeReference(t *testing.T) { func Test_rdfParser2_2_getPointerFromNode(t *testing.T) { var parser *rdfParser2_2 var node *gordfParser.Node - var si *spdx.Snippet2_2 + var si *v2_2.Snippet var err error var rt RangeType var number int @@ -278,7 +280,7 @@ func Test_rdfParser2_2_getPointerFromNode(t *testing.T) { func Test_rdfParser2_2_setSnippetRangeFromNode(t *testing.T) { var parser *rdfParser2_2 var err error - var si *spdx.Snippet2_2 + var si *v2_2.Snippet var node *gordfParser.Node // TestCase 1: range with less one pointer less must raise an error @@ -294,7 +296,7 @@ func Test_rdfParser2_2_setSnippetRangeFromNode(t *testing.T) { `) - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setSnippetRangeFromNode(node, si) if err == nil { @@ -320,7 +322,7 @@ func Test_rdfParser2_2_setSnippetRangeFromNode(t *testing.T) { `) - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} node = parser.gordfParserObj.Triples[0].Subject dummyTriple := parser.gordfParserObj.Triples[0] // resetting the node to be associated with 3 triples which will have @@ -350,7 +352,7 @@ func Test_rdfParser2_2_setSnippetRangeFromNode(t *testing.T) { `) - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setSnippetRangeFromNode(node, si) if err == nil { @@ -374,7 +376,7 @@ func Test_rdfParser2_2_setSnippetRangeFromNode(t *testing.T) { `) - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setSnippetRangeFromNode(node, si) if err == nil { @@ -398,7 +400,7 @@ func Test_rdfParser2_2_setSnippetRangeFromNode(t *testing.T) { `) - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setSnippetRangeFromNode(node, si) if err == nil { @@ -422,7 +424,7 @@ func Test_rdfParser2_2_setSnippetRangeFromNode(t *testing.T) { `) - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setSnippetRangeFromNode(node, si) if err == nil { @@ -446,7 +448,7 @@ func Test_rdfParser2_2_setSnippetRangeFromNode(t *testing.T) { `) - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setSnippetRangeFromNode(node, si) if err == nil { @@ -470,7 +472,7 @@ func Test_rdfParser2_2_setSnippetRangeFromNode(t *testing.T) { `) - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setSnippetRangeFromNode(node, si) if err != nil { @@ -494,7 +496,7 @@ func Test_rdfParser2_2_setSnippetRangeFromNode(t *testing.T) { `) - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} node = parser.gordfParserObj.Triples[0].Subject err = parser.setSnippetRangeFromNode(node, si) if err != nil { @@ -504,22 +506,22 @@ func Test_rdfParser2_2_setSnippetRangeFromNode(t *testing.T) { func Test_rdfParser2_2_setSnippetToFileWithID(t *testing.T) { var parser *rdfParser2_2 - var fileId spdx.ElementID - var si *spdx.Snippet2_2 - var file *spdx.File2_2 + var fileId common.ElementID + var si *v2_2.Snippet + var file *v2_2.File var err error // TestCase 1: file id which is not associated with any file must raise an error. parser, _ = parserFromBodyContent("") - si = &spdx.Snippet2_2{} + si = &v2_2.Snippet{} err = parser.setSnippetToFileWithID(si, fileId) if err == nil { t.Errorf("expected an error saying undefined file") } // TestCase 2: file exists, but snippet of the file doesn't ( it mustn't raise any error ) - fileId = spdx.ElementID("File1") - file = &spdx.File2_2{ + fileId = common.ElementID("File1") + file = &v2_2.File{ FileSPDXIdentifier: fileId, } parser.files[fileId] = file diff --git a/rdfloader/parser2v2/parse_spdx_document.go b/rdfloader/parser2v2/parse_spdx_document.go index 61593172..481e8ccb 100644 --- a/rdfloader/parser2v2/parse_spdx_document.go +++ b/rdfloader/parser2v2/parse_spdx_document.go @@ -4,8 +4,10 @@ package parser2v2 import ( "fmt" + gordfParser "github.com/spdx/gordf/rdfloader/parser" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) func (parser *rdfParser2_2) parseSpdxDocumentNode(spdxDocNode *gordfParser.Node) (err error) { @@ -18,8 +20,8 @@ func (parser *rdfParser2_2) parseSpdxDocumentNode(spdxDocNode *gordfParser.Node) if err != nil { return err } - parser.doc.DocumentNamespace = baseUri // 2.5 - parser.doc.SPDXIdentifier = spdx.ElementID(offset) // 2.3 + parser.doc.DocumentNamespace = baseUri // 2.5 + parser.doc.SPDXIdentifier = common.ElementID(offset) // 2.3 // parse other associated triples. for _, subTriple := range parser.nodeToTriples(spdxDocNode) { @@ -42,7 +44,7 @@ func (parser *rdfParser2_2) parseSpdxDocumentNode(spdxDocNode *gordfParser.Node) parser.doc.DocumentName = objectValue case SPDX_EXTERNAL_DOCUMENT_REF: // 2.6: externalDocumentReferences // cardinality: min 0 - var extRef spdx.ExternalDocumentRef2_2 + var extRef v2_2.ExternalDocumentRef extRef, err = parser.getExternalDocumentRefFromNode(subTriple.Object) if err != nil { return err @@ -59,7 +61,7 @@ func (parser *rdfParser2_2) parseSpdxDocumentNode(spdxDocNode *gordfParser.Node) err = parser.setReviewFromNode(subTriple.Object) case SPDX_DESCRIBES_PACKAGE: // describes Package // cardinality: min 0 - var pkg *spdx.Package2_2 + var pkg *v2_2.Package pkg, err = parser.getPackageFromNode(subTriple.Object) if err != nil { return err @@ -89,7 +91,7 @@ func (parser *rdfParser2_2) parseSpdxDocumentNode(spdxDocNode *gordfParser.Node) return nil } -func (parser *rdfParser2_2) getExternalDocumentRefFromNode(node *gordfParser.Node) (edr spdx.ExternalDocumentRef2_2, err error) { +func (parser *rdfParser2_2) getExternalDocumentRefFromNode(node *gordfParser.Node) (edr v2_2.ExternalDocumentRef, err error) { for _, triple := range parser.nodeToTriples(node) { switch triple.Predicate.ID { case SPDX_EXTERNAL_DOCUMENT_ID: diff --git a/rdfloader/parser2v2/parse_spdx_document_test.go b/rdfloader/parser2v2/parse_spdx_document_test.go index a313479a..9d22faad 100644 --- a/rdfloader/parser2v2/parse_spdx_document_test.go +++ b/rdfloader/parser2v2/parse_spdx_document_test.go @@ -3,8 +3,9 @@ package parser2v2 import ( - gordfParser "github.com/spdx/gordf/rdfloader/parser" "testing" + + gordfParser "github.com/spdx/gordf/rdfloader/parser" ) func Test_rdfParser2_2_getExternalDocumentRefFromNode(t *testing.T) { diff --git a/rdfloader/parser2v2/parser.go b/rdfloader/parser2v2/parser.go index 6329dc49..4b3b62c1 100644 --- a/rdfloader/parser2v2/parser.go +++ b/rdfloader/parser2v2/parser.go @@ -5,9 +5,11 @@ package parser2v2 import ( "errors" "fmt" + gordfParser "github.com/spdx/gordf/rdfloader/parser" gordfWriter "github.com/spdx/gordf/rdfwriter" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // returns a new instance of rdfParser2_2 given the gordf object and nodeToTriples mapping @@ -15,18 +17,18 @@ func NewParser2_2(gordfParserObj *gordfParser.Parser, nodeToTriples map[string][ parser := rdfParser2_2{ gordfParserObj: gordfParserObj, nodeStringToTriples: nodeToTriples, - doc: &spdx.Document2_2{ - ExternalDocumentReferences: []spdx.ExternalDocumentRef2_2{}, - CreationInfo: &spdx.CreationInfo2_2{}, - Packages: []*spdx.Package2_2{}, - Files: []*spdx.File2_2{}, - OtherLicenses: []*spdx.OtherLicense2_2{}, - Relationships: []*spdx.Relationship2_2{}, - Annotations: []*spdx.Annotation2_2{}, - Reviews: []*spdx.Review2_2{}, + doc: &v2_2.Document{ + ExternalDocumentReferences: []v2_2.ExternalDocumentRef{}, + CreationInfo: &v2_2.CreationInfo{}, + Packages: []*v2_2.Package{}, + Files: []*v2_2.File{}, + OtherLicenses: []*v2_2.OtherLicense{}, + Relationships: []*v2_2.Relationship{}, + Annotations: []*v2_2.Annotation{}, + Reviews: []*v2_2.Review{}, }, - files: map[spdx.ElementID]*spdx.File2_2{}, - assocWithPackage: map[spdx.ElementID]bool{}, + files: map[common.ElementID]*v2_2.File{}, + assocWithPackage: map[common.ElementID]bool{}, cache: map[string]*nodeState{}, } return &parser @@ -34,7 +36,7 @@ func NewParser2_2(gordfParserObj *gordfParser.Parser, nodeToTriples map[string][ // main function which takes in a gordfParser and returns // a spdxDocument model or the error encountered while parsing it -func LoadFromGoRDFParser(gordfParserObj *gordfParser.Parser) (*spdx.Document2_2, error) { +func LoadFromGoRDFParser(gordfParserObj *gordfParser.Parser) (*v2_2.Document, error) { // nodeToTriples is a mapping from a node to list of triples. // for every node in the set of subjects of all the triples, // it provides a list of triples that are associated with that subject node. diff --git a/rdfloader/parser2v2/types.go b/rdfloader/parser2v2/types.go index 4d163449..dbb50d5d 100644 --- a/rdfloader/parser2v2/types.go +++ b/rdfloader/parser2v2/types.go @@ -4,7 +4,8 @@ package parser2v2 import ( gordfParser "github.com/spdx/gordf/rdfloader/parser" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) type rdfParser2_2 struct { @@ -14,11 +15,11 @@ type rdfParser2_2 struct { nodeStringToTriples map[string][]*gordfParser.Triple // document into which data is being parsed - doc *spdx.Document2_2 + doc *v2_2.Document // map of packages and files. - files map[spdx.ElementID]*spdx.File2_2 - assocWithPackage map[spdx.ElementID]bool + files map[common.ElementID]*v2_2.File + assocWithPackage map[common.ElementID]bool // mapping of nodeStrings to parsed object to save double computation. cache map[string]*nodeState @@ -27,16 +28,16 @@ type rdfParser2_2 struct { type Color int const ( - GREY Color = iota // represents that the node is being visited - WHITE // unvisited node - BLACK // visited node + GREY Color = iota // represents that the node is being visited + WHITE // unvisited node + BLACK // visited node ) type nodeState struct { // object will be pointer to the parsed or element being parsed. object interface{} // color of a state represents if the node is visited/unvisited/being-visited. - Color Color + Color Color } type AnyLicenseInfo interface { diff --git a/rdfloader/parser2v2/utils.go b/rdfloader/parser2v2/utils.go index 27207d25..9f51a3c6 100644 --- a/rdfloader/parser2v2/utils.go +++ b/rdfloader/parser2v2/utils.go @@ -5,11 +5,12 @@ package parser2v2 import ( "errors" "fmt" + "strings" + gordfParser "github.com/spdx/gordf/rdfloader/parser" "github.com/spdx/gordf/rdfwriter" urilib "github.com/spdx/gordf/uri" - "github.com/spdx/tools-golang/spdx" - "strings" + "github.com/spdx/tools-golang/spdx/common" ) // a uri is of type baseURI#fragment or baseFragment/subFragment @@ -67,7 +68,7 @@ func boolFromString(boolString string) (bool, error) { // used to extract DocumentRef and SPDXRef values from an SPDX Identifier // which can point either to this document or to a different one -func ExtractDocElementID(value string) (spdx.DocElementID, error) { +func ExtractDocElementID(value string) (common.DocElementID, error) { docRefID := "" idStr := value @@ -77,16 +78,16 @@ func ExtractDocElementID(value string) (spdx.DocElementID, error) { strs := strings.Split(idStr, ":") // should be exactly two, part before and part after if len(strs) < 2 { - return spdx.DocElementID{}, fmt.Errorf("no colon found although DocumentRef- prefix present") + return common.DocElementID{}, fmt.Errorf("no colon found although DocumentRef- prefix present") } if len(strs) > 2 { - return spdx.DocElementID{}, fmt.Errorf("more than one colon found") + return common.DocElementID{}, fmt.Errorf("more than one colon found") } // trim the prefix and confirm non-empty docRefID = strings.TrimPrefix(strs[0], "DocumentRef-") if docRefID == "" { - return spdx.DocElementID{}, fmt.Errorf("document identifier has nothing after prefix") + return common.DocElementID{}, fmt.Errorf("document identifier has nothing after prefix") } // and use remainder for element ID parsing idStr = strs[1] @@ -94,48 +95,48 @@ func ExtractDocElementID(value string) (spdx.DocElementID, error) { // check prefix to confirm it's got the right prefix for element IDs if !strings.HasPrefix(idStr, "SPDXRef-") { - return spdx.DocElementID{}, fmt.Errorf("missing SPDXRef- prefix for element identifier") + return common.DocElementID{}, fmt.Errorf("missing SPDXRef- prefix for element identifier") } // make sure no colons are present if strings.Contains(idStr, ":") { // we know this means there was no DocumentRef- prefix, because // we would have handled multiple colons above if it was - return spdx.DocElementID{}, fmt.Errorf("invalid colon in element identifier") + return common.DocElementID{}, fmt.Errorf("invalid colon in element identifier") } // trim the prefix and confirm non-empty eltRefID := strings.TrimPrefix(idStr, "SPDXRef-") if eltRefID == "" { - return spdx.DocElementID{}, fmt.Errorf("element identifier has nothing after prefix") + return common.DocElementID{}, fmt.Errorf("element identifier has nothing after prefix") } // we're good - return spdx.DocElementID{DocumentRefID: docRefID, ElementRefID: spdx.ElementID(eltRefID)}, nil + return common.DocElementID{DocumentRefID: docRefID, ElementRefID: common.ElementID(eltRefID)}, nil } // used to extract SPDXRef values only from an SPDX Identifier which can point // to this document only. Use extractDocElementID for parsing IDs that can // refer either to this document or a different one. -func ExtractElementID(value string) (spdx.ElementID, error) { +func ExtractElementID(value string) (common.ElementID, error) { // check prefix to confirm it's got the right prefix for element IDs if !strings.HasPrefix(value, "SPDXRef-") { - return spdx.ElementID(""), fmt.Errorf("missing SPDXRef- prefix for element identifier") + return common.ElementID(""), fmt.Errorf("missing SPDXRef- prefix for element identifier") } // make sure no colons are present if strings.Contains(value, ":") { - return spdx.ElementID(""), fmt.Errorf("invalid colon in element identifier") + return common.ElementID(""), fmt.Errorf("invalid colon in element identifier") } // trim the prefix and confirm non-empty eltRefID := strings.TrimPrefix(value, "SPDXRef-") if eltRefID == "" { - return spdx.ElementID(""), fmt.Errorf("element identifier has nothing after prefix") + return common.ElementID(""), fmt.Errorf("element identifier has nothing after prefix") } // we're good - return spdx.ElementID(eltRefID), nil + return common.ElementID(eltRefID), nil } // used to extract key / value from embedded substrings diff --git a/rdfloader/parser2v2/utils_test.go b/rdfloader/parser2v2/utils_test.go index 797143be..c0cc5746 100644 --- a/rdfloader/parser2v2/utils_test.go +++ b/rdfloader/parser2v2/utils_test.go @@ -3,10 +3,11 @@ package parser2v2 import ( - gordfParser "github.com/spdx/gordf/rdfloader/parser" - "github.com/spdx/tools-golang/spdx" "reflect" "testing" + + gordfParser "github.com/spdx/gordf/rdfloader/parser" + "github.com/spdx/tools-golang/spdx/common" ) func Test_getLastPartOfURI(t *testing.T) { @@ -223,7 +224,7 @@ func helperForExtractDocElementID(t *testing.T, tst string, wantErr bool, wantDo t.Errorf("testing %v: want %v for DocumentRefID, got %v", tst, wantDoc, deID.DocumentRefID) } } - if deID.ElementRefID != spdx.ElementID(wantElt) { + if deID.ElementRefID != common.ElementID(wantElt) { if wantElt == "" { t.Errorf("testing %v: want emptyString for ElementRefID, got %v", tst, deID.ElementRefID) } else { @@ -259,7 +260,7 @@ func helperForExtractElementID(t *testing.T, tst string, wantErr bool, wantElt s if err == nil && wantErr == true { t.Errorf("testing %v: expected non-nil error, got nil", tst) } - if eID != spdx.ElementID(wantElt) { + if eID != common.ElementID(wantElt) { if wantElt == "" { t.Errorf("testing %v: want emptyString for ElementRefID, got %v", tst, eID) } else { diff --git a/rdfloader/rdfloader.go b/rdfloader/rdfloader.go index d06bd40b..838b0d7e 100644 --- a/rdfloader/rdfloader.go +++ b/rdfloader/rdfloader.go @@ -3,15 +3,16 @@ package rdfloader import ( + "io" + "github.com/spdx/gordf/rdfloader" "github.com/spdx/tools-golang/rdfloader/parser2v2" - "github.com/spdx/tools-golang/spdx" - "io" + "github.com/spdx/tools-golang/spdx/v2_2" ) // Takes in a file Reader and returns the pertaining spdx document // or the error if any is encountered while setting the doc. -func Load2_2(content io.Reader) (*spdx.Document2_2, error) { +func Load2_2(content io.Reader) (*v2_2.Document, error) { var rdfParserObj, err = rdfloader.LoadFromReaderObject(content) if err != nil { return nil, err diff --git a/reporter/reporter.go b/reporter/reporter.go index acb47b5b..3d076681 100644 --- a/reporter/reporter.go +++ b/reporter/reporter.go @@ -10,7 +10,8 @@ import ( "sort" "text/tabwriter" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== 2.1 Reporter functions ===== @@ -18,7 +19,7 @@ import ( // Generate2_1 takes a Package whose Files have been analyzed and an // io.Writer, and outputs to the io.Writer a tabulated count of // the number of Files for each unique LicenseConcluded in the set. -func Generate2_1(pkg *spdx.Package2_1, w io.Writer) error { +func Generate2_1(pkg *v2_1.Package, w io.Writer) error { if pkg.FilesAnalyzed == false { return fmt.Errorf("Package FilesAnalyzed is false") } @@ -56,7 +57,7 @@ func Generate2_1(pkg *spdx.Package2_1, w io.Writer) error { return nil } -func countLicenses2_1(pkg *spdx.Package2_1) (int, int, map[string]int) { +func countLicenses2_1(pkg *v2_1.Package) (int, int, map[string]int) { if pkg == nil || pkg.Files == nil { return 0, 0, nil } @@ -81,7 +82,7 @@ func countLicenses2_1(pkg *spdx.Package2_1) (int, int, map[string]int) { // Generate2_2 takes a Package whose Files have been analyzed and an // io.Writer, and outputs to the io.Writer a tabulated count of // the number of Files for each unique LicenseConcluded in the set. -func Generate2_2(pkg *spdx.Package2_2, w io.Writer) error { +func Generate2_2(pkg *v2_2.Package, w io.Writer) error { if pkg.FilesAnalyzed == false { return fmt.Errorf("Package FilesAnalyzed is false") } @@ -119,7 +120,7 @@ func Generate2_2(pkg *spdx.Package2_2, w io.Writer) error { return nil } -func countLicenses2_2(pkg *spdx.Package2_2) (int, int, map[string]int) { +func countLicenses2_2(pkg *v2_2.Package) (int, int, map[string]int) { if pkg == nil || pkg.Files == nil { return 0, 0, nil } diff --git a/reporter/reporter_test.go b/reporter/reporter_test.go index eceeb7b0..97955933 100644 --- a/reporter/reporter_test.go +++ b/reporter/reporter_test.go @@ -6,14 +6,15 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== 2.1 Reporter top-level function tests ===== func Test2_1ReporterCanMakeReportFromPackage(t *testing.T) { - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ FilesAnalyzed: true, - Files: []*spdx.File2_1{ + Files: []*v2_1.File{ {FileSPDXIdentifier: "File0", LicenseConcluded: "MIT"}, {FileSPDXIdentifier: "File1", LicenseConcluded: "NOASSERTION"}, {FileSPDXIdentifier: "File2", LicenseConcluded: "MIT"}, @@ -54,7 +55,7 @@ func Test2_1ReporterCanMakeReportFromPackage(t *testing.T) { } func Test2_1ReporterReturnsErrorIfPackageFilesNotAnalyzed(t *testing.T) { - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ FilesAnalyzed: false, } @@ -69,9 +70,9 @@ func Test2_1ReporterReturnsErrorIfPackageFilesNotAnalyzed(t *testing.T) { // ===== 2.1 Utility functions ===== func Test2_1CanGetCountsOfLicenses(t *testing.T) { - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ FilesAnalyzed: true, - Files: []*spdx.File2_1{ + Files: []*v2_1.File{ {FileSPDXIdentifier: "File0", LicenseConcluded: "MIT"}, {FileSPDXIdentifier: "File1", LicenseConcluded: "NOASSERTION"}, {FileSPDXIdentifier: "File2", LicenseConcluded: "MIT"}, @@ -120,7 +121,7 @@ func Test2_1NilPackageReturnsZeroCountsOfLicenses(t *testing.T) { t.Fatalf("expected %v, got %v", 0, len(foundCounts)) } - pkg := &spdx.Package2_1{} + pkg := &v2_1.Package{} totalFound, totalNotFound, foundCounts = countLicenses2_1(pkg) if totalFound != 0 { t.Errorf("expected %v, got %v", 0, totalFound) @@ -135,9 +136,9 @@ func Test2_1NilPackageReturnsZeroCountsOfLicenses(t *testing.T) { // ===== 2.2 Reporter top-level function tests ===== func Test2_2ReporterCanMakeReportFromPackage(t *testing.T) { - pkg := &spdx.Package2_2{ + pkg := &v2_2.Package{ FilesAnalyzed: true, - Files: []*spdx.File2_2{ + Files: []*v2_2.File{ {FileSPDXIdentifier: "File0", LicenseConcluded: "MIT"}, {FileSPDXIdentifier: "File1", LicenseConcluded: "NOASSERTION"}, {FileSPDXIdentifier: "File2", LicenseConcluded: "MIT"}, @@ -178,7 +179,7 @@ func Test2_2ReporterCanMakeReportFromPackage(t *testing.T) { } func Test2_2ReporterReturnsErrorIfPackageFilesNotAnalyzed(t *testing.T) { - pkg := &spdx.Package2_2{ + pkg := &v2_2.Package{ FilesAnalyzed: false, } @@ -193,9 +194,9 @@ func Test2_2ReporterReturnsErrorIfPackageFilesNotAnalyzed(t *testing.T) { // ===== 2.2 Utility functions ===== func Test2_2CanGetCountsOfLicenses(t *testing.T) { - pkg := &spdx.Package2_2{ + pkg := &v2_2.Package{ FilesAnalyzed: true, - Files: []*spdx.File2_2{ + Files: []*v2_2.File{ {FileSPDXIdentifier: "File0", LicenseConcluded: "MIT"}, {FileSPDXIdentifier: "File1", LicenseConcluded: "NOASSERTION"}, {FileSPDXIdentifier: "File2", LicenseConcluded: "MIT"}, @@ -244,7 +245,7 @@ func Test2_2NilPackageReturnsZeroCountsOfLicenses(t *testing.T) { t.Fatalf("expected %v, got %v", 0, len(foundCounts)) } - pkg := &spdx.Package2_2{} + pkg := &v2_2.Package{} totalFound, totalNotFound, foundCounts = countLicenses2_2(pkg) if totalFound != 0 { t.Errorf("expected %v, got %v", 0, totalFound) diff --git a/spdxlib/described_elements.go b/spdxlib/described_elements.go index 21d8e7ed..61833b4f 100644 --- a/spdxlib/described_elements.go +++ b/spdxlib/described_elements.go @@ -5,7 +5,10 @@ package spdxlib import ( "fmt" - "github.com/spdx/tools-golang/spdx" + + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" ) // GetDescribedPackageIDs2_1 returns a slice of ElementIDs for all Packages @@ -13,7 +16,7 @@ import ( // - If the document has only one Package, its ID is returned. // - If the document has 2+ Packages, it returns the IDs of those that have // a DESCRIBES (or DESCRIBED_BY) relationship to this DOCUMENT. -func GetDescribedPackageIDs2_1(doc *spdx.Document2_1) ([]spdx.ElementID, error) { +func GetDescribedPackageIDs2_1(doc *v2_1.Document) ([]common.ElementID, error) { // if nil Packages map or zero packages in it, return empty slice if doc.Packages == nil { return nil, fmt.Errorf("Packages map is nil") @@ -24,7 +27,7 @@ func GetDescribedPackageIDs2_1(doc *spdx.Document2_1) ([]spdx.ElementID, error) if len(doc.Packages) == 1 { // get first (only) one and return its ID for _, pkg := range doc.Packages { - return []spdx.ElementID{pkg.PackageSPDXIdentifier}, nil + return []common.ElementID{pkg.PackageSPDXIdentifier}, nil } } @@ -35,8 +38,8 @@ func GetDescribedPackageIDs2_1(doc *spdx.Document2_1) ([]spdx.ElementID, error) return nil, fmt.Errorf("multiple Packages in Document but Relationships slice is nil") } - eIDs, err := FilterRelationships2_1(doc, func(relationship *spdx.Relationship2_1) *spdx.ElementID { - refDocument := spdx.MakeDocElementID("", "DOCUMENT") + eIDs, err := FilterRelationships2_1(doc, func(relationship *v2_1.Relationship) *common.ElementID { + refDocument := common.MakeDocElementID("", "DOCUMENT") if relationship.Relationship == "DESCRIBES" && relationship.RefA == refDocument { return &relationship.RefB.ElementRefID @@ -64,7 +67,7 @@ func GetDescribedPackageIDs2_1(doc *spdx.Document2_1) ([]spdx.ElementID, error) // - If the document has only one Package, its ID is returned. // - If the document has 2+ Packages, it returns the IDs of those that have // a DESCRIBES (or DESCRIBED_BY) relationship to this DOCUMENT. -func GetDescribedPackageIDs2_2(doc *spdx.Document2_2) ([]spdx.ElementID, error) { +func GetDescribedPackageIDs2_2(doc *v2_2.Document) ([]common.ElementID, error) { // if nil Packages map or zero packages in it, return empty slice if doc.Packages == nil { return nil, fmt.Errorf("Packages map is nil") @@ -75,7 +78,7 @@ func GetDescribedPackageIDs2_2(doc *spdx.Document2_2) ([]spdx.ElementID, error) if len(doc.Packages) == 1 { // get first (only) one and return its ID for _, pkg := range doc.Packages { - return []spdx.ElementID{pkg.PackageSPDXIdentifier}, nil + return []common.ElementID{pkg.PackageSPDXIdentifier}, nil } } @@ -86,8 +89,8 @@ func GetDescribedPackageIDs2_2(doc *spdx.Document2_2) ([]spdx.ElementID, error) return nil, fmt.Errorf("multiple Packages in Document but Relationships slice is nil") } - eIDs, err := FilterRelationships2_2(doc, func(relationship *spdx.Relationship2_2) *spdx.ElementID { - refDocument := spdx.MakeDocElementID("", "DOCUMENT") + eIDs, err := FilterRelationships2_2(doc, func(relationship *v2_2.Relationship) *common.ElementID { + refDocument := common.MakeDocElementID("", "DOCUMENT") if relationship.Relationship == "DESCRIBES" && relationship.RefA == refDocument { return &relationship.RefB.ElementRefID diff --git a/spdxlib/described_elements_test.go b/spdxlib/described_elements_test.go index 4c2a1a13..8ea9cd5c 100644 --- a/spdxlib/described_elements_test.go +++ b/spdxlib/described_elements_test.go @@ -5,46 +5,48 @@ package spdxlib import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== 2.1 tests ===== func Test2_1CanGetIDsOfDescribedPackages(t *testing.T) { // set up document and some packages and relationships - doc := &spdx.Document2_1{ + doc := &v2_1.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_1{}, - Packages: []*spdx.Package2_1{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_1.CreationInfo{}, + Packages: []*v2_1.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, {PackageName: "pkg2", PackageSPDXIdentifier: "p2"}, {PackageName: "pkg3", PackageSPDXIdentifier: "p3"}, {PackageName: "pkg4", PackageSPDXIdentifier: "p4"}, {PackageName: "pkg5", PackageSPDXIdentifier: "p5"}, }, - Relationships: []*spdx.Relationship2_1{ - &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p1"), + Relationships: []*v2_1.Relationship{ + &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p1"), Relationship: "DESCRIBES", }, - &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p5"), + &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p5"), Relationship: "DESCRIBES", }, // inverse relationship -- should also get detected - &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "p4"), - RefB: spdx.MakeDocElementID("", "DOCUMENT"), + &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "p4"), + RefB: common.MakeDocElementID("", "DOCUMENT"), Relationship: "DESCRIBED_BY", }, // different relationship - &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "p1"), - RefB: spdx.MakeDocElementID("", "p2"), + &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "p1"), + RefB: common.MakeDocElementID("", "p2"), Relationship: "DEPENDS_ON", }, }, @@ -59,26 +61,26 @@ func Test2_1CanGetIDsOfDescribedPackages(t *testing.T) { if len(describedPkgIDs) != 3 { t.Fatalf("expected %d packages, got %d", 3, len(describedPkgIDs)) } - if describedPkgIDs[0] != spdx.ElementID("p1") { - t.Errorf("expected %v, got %v", spdx.ElementID("p1"), describedPkgIDs[0]) + if describedPkgIDs[0] != common.ElementID("p1") { + t.Errorf("expected %v, got %v", common.ElementID("p1"), describedPkgIDs[0]) } - if describedPkgIDs[1] != spdx.ElementID("p4") { - t.Errorf("expected %v, got %v", spdx.ElementID("p4"), describedPkgIDs[1]) + if describedPkgIDs[1] != common.ElementID("p4") { + t.Errorf("expected %v, got %v", common.ElementID("p4"), describedPkgIDs[1]) } - if describedPkgIDs[2] != spdx.ElementID("p5") { - t.Errorf("expected %v, got %v", spdx.ElementID("p5"), describedPkgIDs[2]) + if describedPkgIDs[2] != common.ElementID("p5") { + t.Errorf("expected %v, got %v", common.ElementID("p5"), describedPkgIDs[2]) } } func Test2_1GetDescribedPackagesReturnsSinglePackageIfOnlyOne(t *testing.T) { // set up document and one package, but no relationships // b/c only one package - doc := &spdx.Document2_1{ + doc := &v2_1.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_1{}, - Packages: []*spdx.Package2_1{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_1.CreationInfo{}, + Packages: []*v2_1.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, }, } @@ -92,30 +94,30 @@ func Test2_1GetDescribedPackagesReturnsSinglePackageIfOnlyOne(t *testing.T) { if len(describedPkgIDs) != 1 { t.Fatalf("expected %d package, got %d", 1, len(describedPkgIDs)) } - if describedPkgIDs[0] != spdx.ElementID("p1") { - t.Errorf("expected %v, got %v", spdx.ElementID("p1"), describedPkgIDs[0]) + if describedPkgIDs[0] != common.ElementID("p1") { + t.Errorf("expected %v, got %v", common.ElementID("p1"), describedPkgIDs[0]) } } func Test2_1FailsToGetDescribedPackagesIfMoreThanOneWithoutDescribesRelationship(t *testing.T) { // set up document and multiple packages, but no DESCRIBES relationships - doc := &spdx.Document2_1{ + doc := &v2_1.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_1{}, - Packages: []*spdx.Package2_1{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_1.CreationInfo{}, + Packages: []*v2_1.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, {PackageName: "pkg2", PackageSPDXIdentifier: "p2"}, {PackageName: "pkg3", PackageSPDXIdentifier: "p3"}, {PackageName: "pkg4", PackageSPDXIdentifier: "p4"}, {PackageName: "pkg5", PackageSPDXIdentifier: "p5"}, }, - Relationships: []*spdx.Relationship2_1{ + Relationships: []*v2_1.Relationship{ // different relationship - &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "p1"), - RefB: spdx.MakeDocElementID("", "p2"), + &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "p1"), + RefB: common.MakeDocElementID("", "p2"), Relationship: "DEPENDS_ON", }, }, @@ -129,12 +131,12 @@ func Test2_1FailsToGetDescribedPackagesIfMoreThanOneWithoutDescribesRelationship func Test2_1FailsToGetDescribedPackagesIfMoreThanOneWithNilRelationships(t *testing.T) { // set up document and multiple packages, but no relationships slice - doc := &spdx.Document2_1{ + doc := &v2_1.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_1{}, - Packages: []*spdx.Package2_1{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_1.CreationInfo{}, + Packages: []*v2_1.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, {PackageName: "pkg2", PackageSPDXIdentifier: "p2"}, }, @@ -148,12 +150,12 @@ func Test2_1FailsToGetDescribedPackagesIfMoreThanOneWithNilRelationships(t *test func Test2_1FailsToGetDescribedPackagesIfZeroPackagesInMap(t *testing.T) { // set up document but no packages - doc := &spdx.Document2_1{ + doc := &v2_1.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_1{}, - Packages: []*spdx.Package2_1{}, + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_1.CreationInfo{}, + Packages: []*v2_1.Package{}, } _, err := GetDescribedPackageIDs2_1(doc) @@ -164,11 +166,11 @@ func Test2_1FailsToGetDescribedPackagesIfZeroPackagesInMap(t *testing.T) { func Test2_1FailsToGetDescribedPackagesIfNilMap(t *testing.T) { // set up document but no packages - doc := &spdx.Document2_1{ + doc := &v2_1.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_1{}, + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_1.CreationInfo{}, } _, err := GetDescribedPackageIDs2_1(doc) @@ -181,39 +183,39 @@ func Test2_1FailsToGetDescribedPackagesIfNilMap(t *testing.T) { func Test2_2CanGetIDsOfDescribedPackages(t *testing.T) { // set up document and some packages and relationships - doc := &spdx.Document2_2{ + doc := &v2_2.Document{ SPDXVersion: "SPDX-2.2", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_2{}, - Packages: []*spdx.Package2_2{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_2.CreationInfo{}, + Packages: []*v2_2.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, {PackageName: "pkg2", PackageSPDXIdentifier: "p2"}, {PackageName: "pkg3", PackageSPDXIdentifier: "p3"}, {PackageName: "pkg4", PackageSPDXIdentifier: "p4"}, {PackageName: "pkg5", PackageSPDXIdentifier: "p5"}, }, - Relationships: []*spdx.Relationship2_2{ - &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p1"), + Relationships: []*v2_2.Relationship{ + &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p1"), Relationship: "DESCRIBES", }, - &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p5"), + &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p5"), Relationship: "DESCRIBES", }, // inverse relationship -- should also get detected - &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "p4"), - RefB: spdx.MakeDocElementID("", "DOCUMENT"), + &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "p4"), + RefB: common.MakeDocElementID("", "DOCUMENT"), Relationship: "DESCRIBED_BY", }, // different relationship - &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "p1"), - RefB: spdx.MakeDocElementID("", "p2"), + &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "p1"), + RefB: common.MakeDocElementID("", "p2"), Relationship: "DEPENDS_ON", }, }, @@ -228,26 +230,26 @@ func Test2_2CanGetIDsOfDescribedPackages(t *testing.T) { if len(describedPkgIDs) != 3 { t.Fatalf("expected %d packages, got %d", 3, len(describedPkgIDs)) } - if describedPkgIDs[0] != spdx.ElementID("p1") { - t.Errorf("expected %v, got %v", spdx.ElementID("p1"), describedPkgIDs[0]) + if describedPkgIDs[0] != common.ElementID("p1") { + t.Errorf("expected %v, got %v", common.ElementID("p1"), describedPkgIDs[0]) } - if describedPkgIDs[1] != spdx.ElementID("p4") { - t.Errorf("expected %v, got %v", spdx.ElementID("p4"), describedPkgIDs[1]) + if describedPkgIDs[1] != common.ElementID("p4") { + t.Errorf("expected %v, got %v", common.ElementID("p4"), describedPkgIDs[1]) } - if describedPkgIDs[2] != spdx.ElementID("p5") { - t.Errorf("expected %v, got %v", spdx.ElementID("p5"), describedPkgIDs[2]) + if describedPkgIDs[2] != common.ElementID("p5") { + t.Errorf("expected %v, got %v", common.ElementID("p5"), describedPkgIDs[2]) } } func Test2_2GetDescribedPackagesReturnsSinglePackageIfOnlyOne(t *testing.T) { // set up document and one package, but no relationships // b/c only one package - doc := &spdx.Document2_2{ + doc := &v2_2.Document{ SPDXVersion: "SPDX-2.2", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_2{}, - Packages: []*spdx.Package2_2{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_2.CreationInfo{}, + Packages: []*v2_2.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, }, } @@ -261,30 +263,30 @@ func Test2_2GetDescribedPackagesReturnsSinglePackageIfOnlyOne(t *testing.T) { if len(describedPkgIDs) != 1 { t.Fatalf("expected %d package, got %d", 1, len(describedPkgIDs)) } - if describedPkgIDs[0] != spdx.ElementID("p1") { - t.Errorf("expected %v, got %v", spdx.ElementID("p1"), describedPkgIDs[0]) + if describedPkgIDs[0] != common.ElementID("p1") { + t.Errorf("expected %v, got %v", common.ElementID("p1"), describedPkgIDs[0]) } } func Test2_2FailsToGetDescribedPackagesIfMoreThanOneWithoutDescribesRelationship(t *testing.T) { // set up document and multiple packages, but no DESCRIBES relationships - doc := &spdx.Document2_2{ + doc := &v2_2.Document{ SPDXVersion: "SPDX-2.2", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_2{}, - Packages: []*spdx.Package2_2{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_2.CreationInfo{}, + Packages: []*v2_2.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, {PackageName: "pkg2", PackageSPDXIdentifier: "p2"}, {PackageName: "pkg3", PackageSPDXIdentifier: "p3"}, {PackageName: "pkg4", PackageSPDXIdentifier: "p4"}, {PackageName: "pkg5", PackageSPDXIdentifier: "p5"}, }, - Relationships: []*spdx.Relationship2_2{ + Relationships: []*v2_2.Relationship{ // different relationship - &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "p1"), - RefB: spdx.MakeDocElementID("", "p2"), + &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "p1"), + RefB: common.MakeDocElementID("", "p2"), Relationship: "DEPENDS_ON", }, }, @@ -298,12 +300,12 @@ func Test2_2FailsToGetDescribedPackagesIfMoreThanOneWithoutDescribesRelationship func Test2_2FailsToGetDescribedPackagesIfMoreThanOneWithNilRelationships(t *testing.T) { // set up document and multiple packages, but no relationships slice - doc := &spdx.Document2_2{ + doc := &v2_2.Document{ SPDXVersion: "SPDX-2.2", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_2{}, - Packages: []*spdx.Package2_2{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_2.CreationInfo{}, + Packages: []*v2_2.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, {PackageName: "pkg2", PackageSPDXIdentifier: "p2"}, }, @@ -317,12 +319,12 @@ func Test2_2FailsToGetDescribedPackagesIfMoreThanOneWithNilRelationships(t *test func Test2_2FailsToGetDescribedPackagesIfZeroPackagesInMap(t *testing.T) { // set up document but no packages - doc := &spdx.Document2_2{ + doc := &v2_2.Document{ SPDXVersion: "SPDX-2.2", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_2{}, - Packages: []*spdx.Package2_2{}, + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_2.CreationInfo{}, + Packages: []*v2_2.Package{}, } _, err := GetDescribedPackageIDs2_2(doc) @@ -333,11 +335,11 @@ func Test2_2FailsToGetDescribedPackagesIfZeroPackagesInMap(t *testing.T) { func Test2_2FailsToGetDescribedPackagesIfNilMap(t *testing.T) { // set up document but no packages - doc := &spdx.Document2_2{ + doc := &v2_2.Document{ SPDXVersion: "SPDX-2.2", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_2{}, + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_2.CreationInfo{}, } _, err := GetDescribedPackageIDs2_2(doc) diff --git a/spdxlib/documents.go b/spdxlib/documents.go index 1f7122a7..8560f082 100644 --- a/spdxlib/documents.go +++ b/spdxlib/documents.go @@ -3,15 +3,18 @@ package spdxlib import ( "fmt" - "github.com/spdx/tools-golang/spdx" + + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ValidateDocument2_1 returns an error if the Document is found to be invalid, or nil if the Document is valid. // Currently, this only verifies that all Element IDs mentioned in Relationships exist in the Document as either a // Package or an UnpackagedFile. -func ValidateDocument2_1(doc *spdx.Document2_1) error { +func ValidateDocument2_1(doc *v2_1.Document) error { // cache a map of valid package IDs for quick lookups - validElementIDs := make(map[spdx.ElementID]bool) + validElementIDs := make(map[common.ElementID]bool) for _, docPackage := range doc.Packages { validElementIDs[docPackage.PackageSPDXIdentifier] = true } @@ -21,7 +24,7 @@ func ValidateDocument2_1(doc *spdx.Document2_1) error { } // add the Document element ID - validElementIDs[spdx.MakeDocElementID("", "DOCUMENT").ElementRefID] = true + validElementIDs[common.MakeDocElementID("", "DOCUMENT").ElementRefID] = true for _, relationship := range doc.Relationships { if !validElementIDs[relationship.RefA.ElementRefID] { @@ -39,9 +42,9 @@ func ValidateDocument2_1(doc *spdx.Document2_1) error { // ValidateDocument2_2 returns an error if the Document is found to be invalid, or nil if the Document is valid. // Currently, this only verifies that all Element IDs mentioned in Relationships exist in the Document as either a // Package or an UnpackagedFile. -func ValidateDocument2_2(doc *spdx.Document2_2) error { +func ValidateDocument2_2(doc *v2_2.Document) error { // cache a map of package IDs for quick lookups - validElementIDs := make(map[spdx.ElementID]bool) + validElementIDs := make(map[common.ElementID]bool) for _, docPackage := range doc.Packages { validElementIDs[docPackage.PackageSPDXIdentifier] = true } @@ -51,7 +54,7 @@ func ValidateDocument2_2(doc *spdx.Document2_2) error { } // add the Document element ID - validElementIDs[spdx.MakeDocElementID("", "DOCUMENT").ElementRefID] = true + validElementIDs[common.MakeDocElementID("", "DOCUMENT").ElementRefID] = true for _, relationship := range doc.Relationships { if !validElementIDs[relationship.RefA.ElementRefID] { diff --git a/spdxlib/documents_test.go b/spdxlib/documents_test.go index aa1f6c35..586cabdd 100644 --- a/spdxlib/documents_test.go +++ b/spdxlib/documents_test.go @@ -5,46 +5,48 @@ package spdxlib import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== 2.1 tests ===== func Test2_1ValidDocumentPassesValidation(t *testing.T) { // set up document and some packages and relationships - doc := &spdx.Document2_1{ + doc := &v2_1.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_1{}, - Packages: []*spdx.Package2_1{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_1.CreationInfo{}, + Packages: []*v2_1.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, {PackageName: "pkg2", PackageSPDXIdentifier: "p2"}, {PackageName: "pkg3", PackageSPDXIdentifier: "p3"}, {PackageName: "pkg4", PackageSPDXIdentifier: "p4"}, {PackageName: "pkg5", PackageSPDXIdentifier: "p5"}, }, - Relationships: []*spdx.Relationship2_1{ + Relationships: []*v2_1.Relationship{ { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p1"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p1"), Relationship: "DESCRIBES", }, { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p5"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p5"), Relationship: "DESCRIBES", }, // inverse relationship -- should also get detected { - RefA: spdx.MakeDocElementID("", "p4"), - RefB: spdx.MakeDocElementID("", "DOCUMENT"), + RefA: common.MakeDocElementID("", "p4"), + RefB: common.MakeDocElementID("", "DOCUMENT"), Relationship: "DESCRIBED_BY", }, // different relationship { - RefA: spdx.MakeDocElementID("", "p1"), - RefB: spdx.MakeDocElementID("", "p2"), + RefA: common.MakeDocElementID("", "p1"), + RefB: common.MakeDocElementID("", "p2"), Relationship: "DEPENDS_ON", }, }, @@ -58,31 +60,31 @@ func Test2_1ValidDocumentPassesValidation(t *testing.T) { func Test2_1InvalidDocumentFailsValidation(t *testing.T) { // set up document and some packages and relationships - doc := &spdx.Document2_1{ + doc := &v2_1.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_1{}, - Packages: []*spdx.Package2_1{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_1.CreationInfo{}, + Packages: []*v2_1.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, {PackageName: "pkg2", PackageSPDXIdentifier: "p2"}, {PackageName: "pkg3", PackageSPDXIdentifier: "p3"}, }, - Relationships: []*spdx.Relationship2_1{ + Relationships: []*v2_1.Relationship{ { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p1"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p1"), Relationship: "DESCRIBES", }, { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p2"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p2"), Relationship: "DESCRIBES", }, // invalid ID p99 { - RefA: spdx.MakeDocElementID("", "p1"), - RefB: spdx.MakeDocElementID("", "p99"), + RefA: common.MakeDocElementID("", "p1"), + RefB: common.MakeDocElementID("", "p99"), Relationship: "DEPENDS_ON", }, }, @@ -98,39 +100,39 @@ func Test2_1InvalidDocumentFailsValidation(t *testing.T) { func Test2_2ValidDocumentPassesValidation(t *testing.T) { // set up document and some packages and relationships - doc := &spdx.Document2_2{ + doc := &v2_2.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_2{}, - Packages: []*spdx.Package2_2{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_2.CreationInfo{}, + Packages: []*v2_2.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, {PackageName: "pkg2", PackageSPDXIdentifier: "p2"}, {PackageName: "pkg3", PackageSPDXIdentifier: "p3"}, {PackageName: "pkg4", PackageSPDXIdentifier: "p4"}, {PackageName: "pkg5", PackageSPDXIdentifier: "p5"}, }, - Relationships: []*spdx.Relationship2_2{ + Relationships: []*v2_2.Relationship{ { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p1"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p1"), Relationship: "DESCRIBES", }, { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p5"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p5"), Relationship: "DESCRIBES", }, // inverse relationship -- should also get detected { - RefA: spdx.MakeDocElementID("", "p4"), - RefB: spdx.MakeDocElementID("", "DOCUMENT"), + RefA: common.MakeDocElementID("", "p4"), + RefB: common.MakeDocElementID("", "DOCUMENT"), Relationship: "DESCRIBED_BY", }, // different relationship { - RefA: spdx.MakeDocElementID("", "p1"), - RefB: spdx.MakeDocElementID("", "p2"), + RefA: common.MakeDocElementID("", "p1"), + RefB: common.MakeDocElementID("", "p2"), Relationship: "DEPENDS_ON", }, }, @@ -144,31 +146,31 @@ func Test2_2ValidDocumentPassesValidation(t *testing.T) { func Test2_2InvalidDocumentFailsValidation(t *testing.T) { // set up document and some packages and relationships - doc := &spdx.Document2_2{ + doc := &v2_2.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_2{}, - Packages: []*spdx.Package2_2{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_2.CreationInfo{}, + Packages: []*v2_2.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, {PackageName: "pkg2", PackageSPDXIdentifier: "p2"}, {PackageName: "pkg3", PackageSPDXIdentifier: "p3"}, }, - Relationships: []*spdx.Relationship2_2{ + Relationships: []*v2_2.Relationship{ { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p1"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p1"), Relationship: "DESCRIBES", }, { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p5"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p5"), Relationship: "DESCRIBES", }, // invalid ID p99 { - RefA: spdx.MakeDocElementID("", "p1"), - RefB: spdx.MakeDocElementID("", "p99"), + RefA: common.MakeDocElementID("", "p1"), + RefB: common.MakeDocElementID("", "p99"), Relationship: "DEPENDS_ON", }, }, diff --git a/spdxlib/element_ids.go b/spdxlib/element_ids.go index f0c5ee00..d505d40f 100644 --- a/spdxlib/element_ids.go +++ b/spdxlib/element_ids.go @@ -3,12 +3,13 @@ package spdxlib import ( - "github.com/spdx/tools-golang/spdx" "sort" + + "github.com/spdx/tools-golang/spdx/common" ) // SortElementIDs sorts and returns the given slice of ElementIDs -func SortElementIDs(eIDs []spdx.ElementID) []spdx.ElementID { +func SortElementIDs(eIDs []common.ElementID) []common.ElementID { sort.Slice(eIDs, func(i, j int) bool { return eIDs[i] < eIDs[j] }) diff --git a/spdxlib/element_ids_test.go b/spdxlib/element_ids_test.go index 3642e165..83893ba5 100644 --- a/spdxlib/element_ids_test.go +++ b/spdxlib/element_ids_test.go @@ -3,16 +3,17 @@ package spdxlib import ( - "github.com/spdx/tools-golang/spdx" "reflect" "testing" + + "github.com/spdx/tools-golang/spdx/common" ) func TestSortElementIDs(t *testing.T) { - eIDs := []spdx.ElementID{"def", "abc", "123"} + eIDs := []common.ElementID{"def", "abc", "123"} eIDs = SortElementIDs(eIDs) - if !reflect.DeepEqual(eIDs, []spdx.ElementID{"123", "abc", "def"}) { + if !reflect.DeepEqual(eIDs, []common.ElementID{"123", "abc", "def"}) { t.Fatalf("expected sorted ElementIDs, got: %v", eIDs) } } diff --git a/spdxlib/relationships.go b/spdxlib/relationships.go index ecc5a19c..5ff41977 100644 --- a/spdxlib/relationships.go +++ b/spdxlib/relationships.go @@ -2,12 +2,16 @@ package spdxlib -import "github.com/spdx/tools-golang/spdx" +import ( + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" +) // FilterRelationships2_1 returns a slice of Element IDs returned by the given filter closure. The closure is passed // one relationship at a time, and it can return an ElementID or nil. -func FilterRelationships2_1(doc *spdx.Document2_1, filter func(*spdx.Relationship2_1) *spdx.ElementID) ([]spdx.ElementID, error) { - elementIDs := []spdx.ElementID{} +func FilterRelationships2_1(doc *v2_1.Document, filter func(*v2_1.Relationship) *common.ElementID) ([]common.ElementID, error) { + elementIDs := []common.ElementID{} for _, relationship := range doc.Relationships { if id := filter(relationship); id != nil { @@ -20,8 +24,8 @@ func FilterRelationships2_1(doc *spdx.Document2_1, filter func(*spdx.Relationshi // FilterRelationships2_2 returns a slice of Element IDs returned by the given filter closure. The closure is passed // one relationship at a time, and it can return an ElementID or nil. -func FilterRelationships2_2(doc *spdx.Document2_2, filter func(*spdx.Relationship2_2) *spdx.ElementID) ([]spdx.ElementID, error) { - elementIDs := []spdx.ElementID{} +func FilterRelationships2_2(doc *v2_2.Document, filter func(*v2_2.Relationship) *common.ElementID) ([]common.ElementID, error) { + elementIDs := []common.ElementID{} for _, relationship := range doc.Relationships { if id := filter(relationship); id != nil { diff --git a/spdxlib/relationships_test.go b/spdxlib/relationships_test.go index e710d6e5..57728877 100644 --- a/spdxlib/relationships_test.go +++ b/spdxlib/relationships_test.go @@ -5,56 +5,58 @@ package spdxlib import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== 2.1 tests ===== func Test2_1FilterForDependencies(t *testing.T) { // set up document and some packages and relationships - doc := &spdx.Document2_1{ + doc := &v2_1.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_1{}, - Packages: []*spdx.Package2_1{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_1.CreationInfo{}, + Packages: []*v2_1.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, {PackageName: "pkg2", PackageSPDXIdentifier: "p2"}, {PackageName: "pkg3", PackageSPDXIdentifier: "p3"}, {PackageName: "pkg4", PackageSPDXIdentifier: "p4"}, {PackageName: "pkg5", PackageSPDXIdentifier: "p5"}, }, - Relationships: []*spdx.Relationship2_1{ + Relationships: []*v2_1.Relationship{ { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p1"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p1"), Relationship: "DESCRIBES", }, { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p5"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p5"), Relationship: "DESCRIBES", }, { - RefA: spdx.MakeDocElementID("", "p4"), - RefB: spdx.MakeDocElementID("", "DOCUMENT"), + RefA: common.MakeDocElementID("", "p4"), + RefB: common.MakeDocElementID("", "DOCUMENT"), Relationship: "DESCRIBED_BY", }, { - RefA: spdx.MakeDocElementID("", "p1"), - RefB: spdx.MakeDocElementID("", "p2"), + RefA: common.MakeDocElementID("", "p1"), + RefB: common.MakeDocElementID("", "p2"), Relationship: "DEPENDS_ON", }, { - RefA: spdx.MakeDocElementID("", "p3"), - RefB: spdx.MakeDocElementID("", "p4"), + RefA: common.MakeDocElementID("", "p3"), + RefB: common.MakeDocElementID("", "p4"), Relationship: "DEPENDENCY_OF", }, }, } - eIDs, err := FilterRelationships2_1(doc, func(relationship *spdx.Relationship2_1) *spdx.ElementID { - p1EID := spdx.MakeDocElementID("", "p1") + eIDs, err := FilterRelationships2_1(doc, func(relationship *v2_1.Relationship) *common.ElementID { + p1EID := common.MakeDocElementID("", "p1") if relationship.Relationship == "DEPENDS_ON" && relationship.RefA == p1EID { return &relationship.RefB.ElementRefID } else if relationship.Relationship == "DEPENDENCY_OF" && relationship.RefB == p1EID { @@ -71,7 +73,7 @@ func Test2_1FilterForDependencies(t *testing.T) { t.Fatalf("expected 1 ElementID, got: %v", eIDs) } - if eIDs[0] != spdx.MakeDocElementID("", "p2").ElementRefID { + if eIDs[0] != common.MakeDocElementID("", "p2").ElementRefID { t.Fatalf("received unexpected relationship: %v", eIDs[0]) } } @@ -80,46 +82,46 @@ func Test2_1FilterForDependencies(t *testing.T) { func Test2_2FindsDependsOnRelationships(t *testing.T) { // set up document and some packages and relationships - doc := &spdx.Document2_2{ + doc := &v2_2.Document{ SPDXVersion: "SPDX-2.2", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), - CreationInfo: &spdx.CreationInfo2_2{}, - Packages: []*spdx.Package2_2{ + SPDXIdentifier: common.ElementID("DOCUMENT"), + CreationInfo: &v2_2.CreationInfo{}, + Packages: []*v2_2.Package{ {PackageName: "pkg1", PackageSPDXIdentifier: "p1"}, {PackageName: "pkg2", PackageSPDXIdentifier: "p2"}, {PackageName: "pkg3", PackageSPDXIdentifier: "p3"}, {PackageName: "pkg4", PackageSPDXIdentifier: "p4"}, {PackageName: "pkg5", PackageSPDXIdentifier: "p5"}, }, - Relationships: []*spdx.Relationship2_2{ + Relationships: []*v2_2.Relationship{ { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p1"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p1"), Relationship: "DESCRIBES", }, { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p5"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p5"), Relationship: "DESCRIBES", }, // inverse relationship -- should also get detected { - RefA: spdx.MakeDocElementID("", "p4"), - RefB: spdx.MakeDocElementID("", "DOCUMENT"), + RefA: common.MakeDocElementID("", "p4"), + RefB: common.MakeDocElementID("", "DOCUMENT"), Relationship: "DESCRIBED_BY", }, // different relationship { - RefA: spdx.MakeDocElementID("", "p1"), - RefB: spdx.MakeDocElementID("", "p2"), + RefA: common.MakeDocElementID("", "p1"), + RefB: common.MakeDocElementID("", "p2"), Relationship: "DEPENDS_ON", }, }, } - eIDs, err := FilterRelationships2_2(doc, func(relationship *spdx.Relationship2_2) *spdx.ElementID { - p1EID := spdx.MakeDocElementID("", "p1") + eIDs, err := FilterRelationships2_2(doc, func(relationship *v2_2.Relationship) *common.ElementID { + p1EID := common.MakeDocElementID("", "p1") if relationship.Relationship == "DEPENDS_ON" && relationship.RefA == p1EID { return &relationship.RefB.ElementRefID } else if relationship.Relationship == "DEPENDENCY_OF" && relationship.RefB == p1EID { @@ -136,7 +138,7 @@ func Test2_2FindsDependsOnRelationships(t *testing.T) { t.Fatalf("expected 1 ElementID, got: %v", eIDs) } - if eIDs[0] != spdx.MakeDocElementID("", "p2").ElementRefID { + if eIDs[0] != common.MakeDocElementID("", "p2").ElementRefID { t.Fatalf("received unexpected relationship: %v", eIDs[0]) } } diff --git a/tvloader/parser2v1/parse_annotation_test.go b/tvloader/parser2v1/parse_annotation_test.go index eb0f4cf5..41fe6a5a 100644 --- a/tvloader/parser2v1/parse_annotation_test.go +++ b/tvloader/parser2v1/parse_annotation_test.go @@ -4,13 +4,13 @@ package parser2v1 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Annotation section tests ===== func TestParser2_1FailsIfAnnotationNotSet(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } err := parser.parsePairForAnnotation2_1("Annotator", "Person: John Doe (jdoe@example.com)") @@ -21,7 +21,7 @@ func TestParser2_1FailsIfAnnotationNotSet(t *testing.T) { func TestParser2_1FailsIfAnnotationTagUnknown(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } // start with valid annotator @@ -38,7 +38,7 @@ func TestParser2_1FailsIfAnnotationTagUnknown(t *testing.T) { func TestParser2_1FailsIfAnnotationFieldsWithoutAnnotation(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } err := parser.parsePair2_1("AnnotationDate", "2018-09-15T17:25:00Z") @@ -61,7 +61,7 @@ func TestParser2_1FailsIfAnnotationFieldsWithoutAnnotation(t *testing.T) { func TestParser2_1CanParseAnnotationTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -121,7 +121,7 @@ func TestParser2_1CanParseAnnotationTags(t *testing.T) { func TestParser2_1FailsIfAnnotatorInvalid(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } err := parser.parsePair2_1("Annotator", "John Doe (jdoe@example.com)") @@ -132,7 +132,7 @@ func TestParser2_1FailsIfAnnotatorInvalid(t *testing.T) { func TestParser2_1FailsIfAnnotatorTypeInvalid(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } err := parser.parsePair2_1("Annotator", "Human: John Doe (jdoe@example.com)") @@ -143,7 +143,7 @@ func TestParser2_1FailsIfAnnotatorTypeInvalid(t *testing.T) { func TestParser2_1FailsIfAnnotationRefInvalid(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } // start with valid annotator diff --git a/tvloader/parser2v1/parse_creation_info.go b/tvloader/parser2v1/parse_creation_info.go index df16008b..d7ca6876 100644 --- a/tvloader/parser2v1/parse_creation_info.go +++ b/tvloader/parser2v1/parse_creation_info.go @@ -6,7 +6,8 @@ import ( "fmt" "strings" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) func (parser *tvParser2_1) parsePairFromCreationInfo2_1(tag string, value string) error { @@ -17,7 +18,7 @@ func (parser *tvParser2_1) parsePairFromCreationInfo2_1(tag string, value string // create an SPDX Creation Info data struct if we don't have one already if parser.doc.CreationInfo == nil { - parser.doc.CreationInfo = &spdx.CreationInfo2_1{} + parser.doc.CreationInfo = &v2_1.CreationInfo{} } ci := parser.doc.CreationInfo @@ -30,7 +31,7 @@ func (parser *tvParser2_1) parsePairFromCreationInfo2_1(tag string, value string return err } - creator := spdx.Creator{Creator: subvalue} + creator := common.Creator{Creator: subvalue} switch subkey { case "Person", "Organization", "Tool": creator.CreatorType = subkey @@ -54,7 +55,7 @@ func (parser *tvParser2_1) parsePairFromCreationInfo2_1(tag string, value string return fmt.Errorf("file with FileName %s does not have SPDX identifier", parser.file.FileName) } parser.st = psPackage2_1 - parser.pkg = &spdx.Package2_1{ + parser.pkg = &v2_1.Package{ FilesAnalyzed: true, IsFilesAnalyzedTagPresent: false, } @@ -75,14 +76,14 @@ func (parser *tvParser2_1) parsePairFromCreationInfo2_1(tag string, value string return parser.parsePairFromReview2_1(tag, value) // for relationship tags, pass along but don't change state case "Relationship": - parser.rln = &spdx.Relationship2_1{} + parser.rln = &v2_1.Relationship{} parser.doc.Relationships = append(parser.doc.Relationships, parser.rln) return parser.parsePairForRelationship2_1(tag, value) case "RelationshipComment": return parser.parsePairForRelationship2_1(tag, value) // for annotation tags, pass along but don't change state case "Annotator": - parser.ann = &spdx.Annotation2_1{} + parser.ann = &v2_1.Annotation{} parser.doc.Annotations = append(parser.doc.Annotations, parser.ann) return parser.parsePairForAnnotation2_1(tag, value) case "AnnotationDate": diff --git a/tvloader/parser2v1/parse_creation_info_test.go b/tvloader/parser2v1/parse_creation_info_test.go index 83058dd8..867491af 100644 --- a/tvloader/parser2v1/parse_creation_info_test.go +++ b/tvloader/parser2v1/parse_creation_info_test.go @@ -4,13 +4,13 @@ package parser2v1 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Parser creation info state change tests ===== func TestParser2_1CIMovesToPackageAfterParsingPackageNameTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } pkgName := "testPkg" @@ -46,7 +46,7 @@ func TestParser2_1CIMovesToPackageAfterParsingPackageNameTag(t *testing.T) { func TestParser2_1CIMovesToFileAfterParsingFileNameTagWithNoPackages(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } err := parser.parsePair2_1("FileName", "testFile") @@ -66,7 +66,7 @@ func TestParser2_1CIMovesToFileAfterParsingFileNameTagWithNoPackages(t *testing. func TestParser2_1CIMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } err := parser.parsePair2_1("LicenseID", "LicenseRef-TestLic") @@ -80,7 +80,7 @@ func TestParser2_1CIMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing.T) { func TestParser2_1CIMovesToReviewAfterParsingReviewerTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } err := parser.parsePair2_1("Reviewer", "Person: John Doe") @@ -94,7 +94,7 @@ func TestParser2_1CIMovesToReviewAfterParsingReviewerTag(t *testing.T) { func TestParser2_1CIStaysAfterParsingRelationshipTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -117,7 +117,7 @@ func TestParser2_1CIStaysAfterParsingRelationshipTags(t *testing.T) { func TestParser2_1CIStaysAfterParsingAnnotationTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -164,7 +164,7 @@ func TestParser2_1CIStaysAfterParsingAnnotationTags(t *testing.T) { func TestParser2_1FailsParsingCreationInfoWithInvalidState(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psPackage2_1, } err := parser.parsePairFromCreationInfo2_1("SPDXVersion", "SPDX-2.1") @@ -176,7 +176,7 @@ func TestParser2_1FailsParsingCreationInfoWithInvalidState(t *testing.T) { // ===== Creation Info section tests ===== func TestParser2_1HasCreationInfoAfterCallToParseFirstTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } err := parser.parsePairFromCreationInfo2_1("LicenseListVersion", "3.9") @@ -190,7 +190,7 @@ func TestParser2_1HasCreationInfoAfterCallToParseFirstTag(t *testing.T) { func TestParser2_1CanParseCreationInfoTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -281,7 +281,7 @@ func TestParser2_1CanParseCreationInfoTags(t *testing.T) { func TestParser2_1InvalidCreatorTagsFail(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -298,7 +298,7 @@ func TestParser2_1InvalidCreatorTagsFail(t *testing.T) { func TestParser2_1CreatorTagWithMultipleColonsPasses(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -310,7 +310,7 @@ func TestParser2_1CreatorTagWithMultipleColonsPasses(t *testing.T) { func TestParser2_1CIUnknownTagFails(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -322,7 +322,7 @@ func TestParser2_1CIUnknownTagFails(t *testing.T) { func TestParser2_1CICreatesRelationship(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -340,7 +340,7 @@ func TestParser2_1CICreatesRelationship(t *testing.T) { func TestParser2_1CICreatesAnnotation(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } diff --git a/tvloader/parser2v1/parse_file.go b/tvloader/parser2v1/parse_file.go index 81768bb6..8ecc2803 100644 --- a/tvloader/parser2v1/parse_file.go +++ b/tvloader/parser2v1/parse_file.go @@ -5,7 +5,8 @@ package parser2v1 import ( "fmt" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) func (parser *tvParser2_1) parsePairFromFile2_1(tag string, value string) error { @@ -22,7 +23,7 @@ func (parser *tvParser2_1) parsePairFromFile2_1(tag string, value string) error if parser.file != nil && parser.file.FileSPDXIdentifier == nullSpdxElementId2_1 { return fmt.Errorf("file with FileName %s does not have SPDX identifier", parser.file.FileName) } - parser.file = &spdx.File2_1{} + parser.file = &v2_1.File{} parser.file.FileName = value // tag for creating new package section and going back to parsing Package case "PackageName": @@ -50,12 +51,12 @@ func (parser *tvParser2_1) parsePairFromFile2_1(tag string, value string) error parser.file.FileSPDXIdentifier = eID if parser.pkg == nil { if parser.doc.Files == nil { - parser.doc.Files = []*spdx.File2_1{} + parser.doc.Files = []*v2_1.File{} } parser.doc.Files = append(parser.doc.Files, parser.file) } else { if parser.pkg.Files == nil { - parser.pkg.Files = []*spdx.File2_1{} + parser.pkg.Files = []*v2_1.File{} } parser.pkg.Files = append(parser.pkg.Files, parser.file) } @@ -67,12 +68,12 @@ func (parser *tvParser2_1) parsePairFromFile2_1(tag string, value string) error return err } if parser.file.Checksums == nil { - parser.file.Checksums = []spdx.Checksum{} + parser.file.Checksums = []common.Checksum{} } - switch spdx.ChecksumAlgorithm(subkey) { - case spdx.SHA1, spdx.SHA256, spdx.MD5: - algorithm := spdx.ChecksumAlgorithm(subkey) - parser.file.Checksums = append(parser.file.Checksums, spdx.Checksum{Algorithm: algorithm, Value: subvalue}) + switch common.ChecksumAlgorithm(subkey) { + case common.SHA1, common.SHA256, common.MD5: + algorithm := common.ChecksumAlgorithm(subkey) + parser.file.Checksums = append(parser.file.Checksums, common.Checksum{Algorithm: algorithm, Value: subvalue}) default: return fmt.Errorf("got unknown checksum type %s", subkey) } @@ -85,7 +86,7 @@ func (parser *tvParser2_1) parsePairFromFile2_1(tag string, value string) error case "FileCopyrightText": parser.file.FileCopyrightText = value case "ArtifactOfProjectName": - parser.fileAOP = &spdx.ArtifactOfProject2_1{} + parser.fileAOP = &v2_1.ArtifactOfProject{} parser.file.ArtifactOfProjects = append(parser.file.ArtifactOfProjects, parser.fileAOP) parser.fileAOP.Name = value case "ArtifactOfProjectHomePage": @@ -108,14 +109,14 @@ func (parser *tvParser2_1) parsePairFromFile2_1(tag string, value string) error parser.file.FileDependencies = append(parser.file.FileDependencies, value) // for relationship tags, pass along but don't change state case "Relationship": - parser.rln = &spdx.Relationship2_1{} + parser.rln = &v2_1.Relationship{} parser.doc.Relationships = append(parser.doc.Relationships, parser.rln) return parser.parsePairForRelationship2_1(tag, value) case "RelationshipComment": return parser.parsePairForRelationship2_1(tag, value) // for annotation tags, pass along but don't change state case "Annotator": - parser.ann = &spdx.Annotation2_1{} + parser.ann = &v2_1.Annotation{} parser.doc.Annotations = append(parser.doc.Annotations, parser.ann) return parser.parsePairForAnnotation2_1(tag, value) case "AnnotationDate": diff --git a/tvloader/parser2v1/parse_file_test.go b/tvloader/parser2v1/parse_file_test.go index 375f9677..33f4ef22 100644 --- a/tvloader/parser2v1/parse_file_test.go +++ b/tvloader/parser2v1/parse_file_test.go @@ -4,7 +4,8 @@ package parser2v1 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Parser file section state change tests ===== @@ -13,10 +14,10 @@ func TestParser2_1FileStartsNewFileAfterParsingFileNameTag(t *testing.T) { fileOldName := "f1.txt" parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: fileOldName, FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: fileOldName, FileSPDXIdentifier: "f1"}, } fileOld := parser.file parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -88,7 +89,7 @@ func TestParser2_1FileStartsNewFileAfterParsingFileNameTag(t *testing.T) { func TestParser2_1FileAddsToPackageOrUnpackagedFiles(t *testing.T) { // start with no packages parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -149,10 +150,10 @@ func TestParser2_1FileStartsNewPackageAfterParsingPackageNameTag(t *testing.T) { f1Name := "f1.txt" parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: p1Name, PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: f1Name, FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: p1Name, PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: f1Name, FileSPDXIdentifier: "f1"}, } p1 := parser.pkg f1 := parser.file @@ -217,10 +218,10 @@ func TestParser2_1FileStartsNewPackageAfterParsingPackageNameTag(t *testing.T) { func TestParser2_1FileMovesToSnippetAfterParsingSnippetSPDXIDTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -242,10 +243,10 @@ func TestParser2_1FileMovesToSnippetAfterParsingSnippetSPDXIDTag(t *testing.T) { func TestParser2_1FileMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -261,10 +262,10 @@ func TestParser2_1FileMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing.T) func TestParser2_1FileMovesToReviewAfterParsingReviewerTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -280,10 +281,10 @@ func TestParser2_1FileMovesToReviewAfterParsingReviewerTag(t *testing.T) { func TestParser2_1FileStaysAfterParsingRelationshipTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -309,10 +310,10 @@ func TestParser2_1FileStaysAfterParsingRelationshipTags(t *testing.T) { func TestParser2_1FileStaysAfterParsingAnnotationTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -361,9 +362,9 @@ func TestParser2_1FileStaysAfterParsingAnnotationTags(t *testing.T) { // ===== File data section tests ===== func TestParser2_1CanParseFileTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -445,15 +446,15 @@ func TestParser2_1CanParseFileTags(t *testing.T) { } for _, checksum := range parser.file.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != codeSha1 { t.Errorf("expected %s for FileChecksumSHA1, got %s", codeSha1, checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != codeSha256 { t.Errorf("expected %s for FileChecksumSHA1, got %s", codeSha256, checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != codeMd5 { t.Errorf("expected %s for FileChecksumSHA1, got %s", codeMd5, checksum.Value) } @@ -676,10 +677,10 @@ func TestParser2_1CanParseFileTags(t *testing.T) { func TestParser2_1FileCreatesRelationshipInDocument(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -698,10 +699,10 @@ func TestParser2_1FileCreatesRelationshipInDocument(t *testing.T) { func TestParser2_1FileCreatesAnnotationInDocument(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -720,10 +721,10 @@ func TestParser2_1FileCreatesAnnotationInDocument(t *testing.T) { func TestParser2_1FileUnknownTagFails(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -736,10 +737,10 @@ func TestParser2_1FileUnknownTagFails(t *testing.T) { func TestFileAOPPointerChangesAfterTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -793,9 +794,9 @@ func TestFileAOPPointerChangesAfterTags(t *testing.T) { func TestParser2_1FailsIfInvalidSPDXIDInFileSection(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -813,9 +814,9 @@ func TestParser2_1FailsIfInvalidSPDXIDInFileSection(t *testing.T) { func TestParser2_1FailsIfInvalidChecksumFormatInFileSection(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -833,9 +834,9 @@ func TestParser2_1FailsIfInvalidChecksumFormatInFileSection(t *testing.T) { func TestParser2_1FailsIfUnknownChecksumTypeInFileSection(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -853,9 +854,9 @@ func TestParser2_1FailsIfUnknownChecksumTypeInFileSection(t *testing.T) { func TestParser2_1FailsIfArtifactHomePageBeforeArtifactName(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -873,9 +874,9 @@ func TestParser2_1FailsIfArtifactHomePageBeforeArtifactName(t *testing.T) { func TestParser2_1FailsIfArtifactURIBeforeArtifactName(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -894,9 +895,9 @@ func TestParser2_1FailsIfArtifactURIBeforeArtifactName(t *testing.T) { func TestParser2_1FilesWithoutSpdxIdThrowError(t *testing.T) { // case 1: The previous file (packaged or unpackaged) does not contain spdxID parser1 := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, - file: &spdx.File2_1{FileName: "FileName"}, + file: &v2_1.File{FileName: "FileName"}, } err := parser1.parsePair2_1("FileName", "f2") @@ -906,12 +907,12 @@ func TestParser2_1FilesWithoutSpdxIdThrowError(t *testing.T) { // case 2: Invalid file with snippet // Last unpackaged file before a snippet starts - sid1 := spdx.ElementID("s1") + sid1 := common.ElementID("s1") fileName := "f2.txt" parser2 := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, - file: &spdx.File2_1{FileName: fileName}, + file: &v2_1.File{FileName: fileName}, } err = parser2.parsePair2_1("SnippetSPDXID", string(sid1)) if err == nil { @@ -922,7 +923,7 @@ func TestParser2_1FilesWithoutSpdxIdThrowError(t *testing.T) { // Last unpackaged file before a package starts // Last file of a package and New package starts parser3 := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } fileName = "f3.txt" diff --git a/tvloader/parser2v1/parse_other_license.go b/tvloader/parser2v1/parse_other_license.go index 3090a890..a2c3d00c 100644 --- a/tvloader/parser2v1/parse_other_license.go +++ b/tvloader/parser2v1/parse_other_license.go @@ -5,14 +5,14 @@ package parser2v1 import ( "fmt" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) func (parser *tvParser2_1) parsePairFromOtherLicense2_1(tag string, value string) error { switch tag { // tag for creating new other license section case "LicenseID": - parser.otherLic = &spdx.OtherLicense2_1{} + parser.otherLic = &v2_1.OtherLicense{} parser.doc.OtherLicenses = append(parser.doc.OtherLicenses, parser.otherLic) parser.otherLic.LicenseIdentifier = value case "ExtractedText": @@ -25,14 +25,14 @@ func (parser *tvParser2_1) parsePairFromOtherLicense2_1(tag string, value string parser.otherLic.LicenseComment = value // for relationship tags, pass along but don't change state case "Relationship": - parser.rln = &spdx.Relationship2_1{} + parser.rln = &v2_1.Relationship{} parser.doc.Relationships = append(parser.doc.Relationships, parser.rln) return parser.parsePairForRelationship2_1(tag, value) case "RelationshipComment": return parser.parsePairForRelationship2_1(tag, value) // for annotation tags, pass along but don't change state case "Annotator": - parser.ann = &spdx.Annotation2_1{} + parser.ann = &v2_1.Annotation{} parser.doc.Annotations = append(parser.doc.Annotations, parser.ann) return parser.parsePairForAnnotation2_1(tag, value) case "AnnotationDate": diff --git a/tvloader/parser2v1/parse_other_license_test.go b/tvloader/parser2v1/parse_other_license_test.go index 5ae520b9..b1b74715 100644 --- a/tvloader/parser2v1/parse_other_license_test.go +++ b/tvloader/parser2v1/parse_other_license_test.go @@ -4,7 +4,7 @@ package parser2v1 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Parser other license section state change tests ===== @@ -14,11 +14,11 @@ func TestParser2_1OLStartsNewOtherLicenseAfterParsingLicenseIDTag(t *testing.T) olname1 := "License 11" parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psOtherLicense2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: olid1, LicenseName: olname1, }, @@ -90,10 +90,10 @@ func TestParser2_1OLStartsNewOtherLicenseAfterParsingLicenseIDTag(t *testing.T) func TestParser2_1OLMovesToReviewAfterParsingReviewerTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psOtherLicense2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -110,11 +110,11 @@ func TestParser2_1OLMovesToReviewAfterParsingReviewerTag(t *testing.T) { func TestParser2_1OtherLicenseStaysAfterParsingRelationshipTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psOtherLicense2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-whatever", LicenseName: "the whatever license", }, @@ -152,11 +152,11 @@ func TestParser2_1OtherLicenseStaysAfterParsingRelationshipTags(t *testing.T) { func TestParser2_1OtherLicenseStaysAfterParsingAnnotationTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psOtherLicense2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-whatever", LicenseName: "the whatever license", }, @@ -216,11 +216,11 @@ func TestParser2_1OtherLicenseStaysAfterParsingAnnotationTags(t *testing.T) { func TestParser2_1OLFailsAfterParsingOtherSectionTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psOtherLicense2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, @@ -247,10 +247,10 @@ func TestParser2_1OLFailsAfterParsingOtherSectionTags(t *testing.T) { // ===== Other License data section tests ===== func TestParser2_1CanParseOtherLicenseTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psOtherLicense2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -323,10 +323,10 @@ func TestParser2_1CanParseOtherLicenseTags(t *testing.T) { func TestParser2_1OLUnknownTagFails(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psOtherLicense2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) diff --git a/tvloader/parser2v1/parse_package.go b/tvloader/parser2v1/parse_package.go index 22fc1ed2..7a3e2a82 100644 --- a/tvloader/parser2v1/parse_package.go +++ b/tvloader/parser2v1/parse_package.go @@ -6,7 +6,8 @@ import ( "fmt" "strings" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) func (parser *tvParser2_1) parsePairFromPackage2_1(tag string, value string) error { @@ -24,7 +25,7 @@ func (parser *tvParser2_1) parsePairFromPackage2_1(tag string, value string) err if parser.pkg != nil && parser.pkg.PackageSPDXIdentifier == nullSpdxElementId2_1 { return fmt.Errorf("package with PackageName %s does not have SPDX identifier", parser.pkg.PackageName) } - parser.pkg = &spdx.Package2_1{ + parser.pkg = &v2_1.Package{ FilesAnalyzed: true, IsFilesAnalyzedTagPresent: false, } @@ -45,7 +46,7 @@ func (parser *tvParser2_1) parsePairFromPackage2_1(tag string, value string) err } parser.pkg.PackageSPDXIdentifier = eID if parser.doc.Packages == nil { - parser.doc.Packages = []*spdx.Package2_1{} + parser.doc.Packages = []*v2_1.Package{} } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) case "PackageVersion": @@ -53,7 +54,7 @@ func (parser *tvParser2_1) parsePairFromPackage2_1(tag string, value string) err case "PackageFileName": parser.pkg.PackageFileName = value case "PackageSupplier": - parser.pkg.PackageSupplier = &spdx.Supplier{} + parser.pkg.PackageSupplier = &common.Supplier{} if value == "NOASSERTION" { parser.pkg.PackageSupplier.Supplier = value break @@ -70,7 +71,7 @@ func (parser *tvParser2_1) parsePairFromPackage2_1(tag string, value string) err return fmt.Errorf("unrecognized PackageSupplier type %v", subkey) } case "PackageOriginator": - parser.pkg.PackageOriginator = &spdx.Originator{} + parser.pkg.PackageOriginator = &common.Originator{} if value == "NOASSERTION" { parser.pkg.PackageOriginator.Originator = value break @@ -103,12 +104,12 @@ func (parser *tvParser2_1) parsePairFromPackage2_1(tag string, value string) err return err } if parser.pkg.PackageChecksums == nil { - parser.pkg.PackageChecksums = []spdx.Checksum{} + parser.pkg.PackageChecksums = []common.Checksum{} } - switch spdx.ChecksumAlgorithm(subkey) { - case spdx.SHA1, spdx.SHA256, spdx.MD5: - algorithm := spdx.ChecksumAlgorithm(subkey) - parser.pkg.PackageChecksums = append(parser.pkg.PackageChecksums, spdx.Checksum{Algorithm: algorithm, Value: subvalue}) + switch common.ChecksumAlgorithm(subkey) { + case common.SHA1, common.SHA256, common.MD5: + algorithm := common.ChecksumAlgorithm(subkey) + parser.pkg.PackageChecksums = append(parser.pkg.PackageChecksums, common.Checksum{Algorithm: algorithm, Value: subvalue}) default: return fmt.Errorf("got unknown checksum type %s", subkey) } @@ -133,7 +134,7 @@ func (parser *tvParser2_1) parsePairFromPackage2_1(tag string, value string) err case "PackageComment": parser.pkg.PackageComment = value case "ExternalRef": - parser.pkgExtRef = &spdx.PackageExternalReference2_1{} + parser.pkgExtRef = &v2_1.PackageExternalReference{} parser.pkg.PackageExternalReferences = append(parser.pkg.PackageExternalReferences, parser.pkgExtRef) category, refType, locator, err := extractPackageExternalReference(value) if err != nil { @@ -151,14 +152,14 @@ func (parser *tvParser2_1) parsePairFromPackage2_1(tag string, value string) err parser.pkgExtRef = nil // for relationship tags, pass along but don't change state case "Relationship": - parser.rln = &spdx.Relationship2_1{} + parser.rln = &v2_1.Relationship{} parser.doc.Relationships = append(parser.doc.Relationships, parser.rln) return parser.parsePairForRelationship2_1(tag, value) case "RelationshipComment": return parser.parsePairForRelationship2_1(tag, value) // for annotation tags, pass along but don't change state case "Annotator": - parser.ann = &spdx.Annotation2_1{} + parser.ann = &v2_1.Annotation{} parser.doc.Annotations = append(parser.doc.Annotations, parser.ann) return parser.parsePairForAnnotation2_1(tag, value) case "AnnotationDate": @@ -182,13 +183,13 @@ func (parser *tvParser2_1) parsePairFromPackage2_1(tag string, value string) err // ===== Helper functions ===== -func extractCodeAndExcludes(value string) spdx.PackageVerificationCode { +func extractCodeAndExcludes(value string) common.PackageVerificationCode { // FIXME this should probably be done using regular expressions instead // split by paren + word "excludes:" sp := strings.SplitN(value, "(excludes:", 2) if len(sp) < 2 { // not found; return the whole string as just the code - return spdx.PackageVerificationCode{Value: value, ExcludedFiles: []string{}} + return common.PackageVerificationCode{Value: value, ExcludedFiles: []string{}} } // if we're here, code is in first part and excludes filename is in @@ -196,7 +197,7 @@ func extractCodeAndExcludes(value string) spdx.PackageVerificationCode { code := strings.TrimSpace(sp[0]) parsedSp := strings.SplitN(sp[1], ")", 2) fileName := strings.TrimSpace(parsedSp[0]) - return spdx.PackageVerificationCode{Value: code, ExcludedFiles: []string{fileName}} + return common.PackageVerificationCode{Value: code, ExcludedFiles: []string{fileName}} } func extractPackageExternalReference(value string) (string, string, string, error) { diff --git a/tvloader/parser2v1/parse_package_test.go b/tvloader/parser2v1/parse_package_test.go index 734fc913..7189ba38 100644 --- a/tvloader/parser2v1/parse_package_test.go +++ b/tvloader/parser2v1/parse_package_test.go @@ -4,7 +4,8 @@ package parser2v1 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Parser package section state change tests ===== @@ -13,9 +14,9 @@ func TestParser2_1PackageStartsNewPackageAfterParsingPackageNameTag(t *testing.T pkgOldName := "p1" parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: pkgOldName, PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: pkgOldName, PackageSPDXIdentifier: "p1"}, } pkgOld := parser.pkg parser.doc.Packages = append(parser.doc.Packages, pkgOld) @@ -62,7 +63,7 @@ func TestParser2_1PackageStartsNewPackageAfterParsingPackageNameTagWhileInUnpack // pkg is nil, so that Files appearing before the first PackageName tag // are added to Files instead of Packages parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psFile2_1, pkg: nil, } @@ -105,9 +106,9 @@ func TestParser2_1PackageStartsNewPackageAfterParsingPackageNameTagWhileInUnpack func TestParser2_1PackageMovesToFileAfterParsingFileNameTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) pkgCurrent := parser.pkg @@ -128,9 +129,9 @@ func TestParser2_1PackageMovesToFileAfterParsingFileNameTag(t *testing.T) { func TestParser2_1PackageMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -145,9 +146,9 @@ func TestParser2_1PackageMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing. func TestParser2_1PackageMovesToReviewAfterParsingReviewerTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -162,9 +163,9 @@ func TestParser2_1PackageMovesToReviewAfterParsingReviewerTag(t *testing.T) { func TestParser2_1PackageStaysAfterParsingRelationshipTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -189,9 +190,9 @@ func TestParser2_1PackageStaysAfterParsingRelationshipTags(t *testing.T) { func TestParser2_1PackageStaysAfterParsingAnnotationTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -239,9 +240,9 @@ func TestParser2_1PackageStaysAfterParsingAnnotationTags(t *testing.T) { // ===== Package data section tests ===== func TestParser2_1CanParsePackageTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{}, + pkg: &v2_1.Package{}, } // should not yet be in Packages map, b/c no SPDX identifier @@ -349,15 +350,15 @@ func TestParser2_1CanParsePackageTags(t *testing.T) { for _, checksum := range parser.pkg.PackageChecksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != codeSha1 { t.Errorf("expected %s for PackageChecksum SHA1, got %s", codeSha1, checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != codeSha256 { t.Errorf("expected %s for PackageChecksum SHA256, got %s", codeSha256, checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != codeMd5 { t.Errorf("expected %s for PackageChecksum MD5, got %s", codeMd5, checksum.Value) } @@ -556,9 +557,9 @@ func TestParser2_1CanParsePackageTags(t *testing.T) { func TestParser2_1CanParsePackageSupplierPersonTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -574,9 +575,9 @@ func TestParser2_1CanParsePackageSupplierPersonTag(t *testing.T) { func TestParser2_1CanParsePackageSupplierOrganizationTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -592,9 +593,9 @@ func TestParser2_1CanParsePackageSupplierOrganizationTag(t *testing.T) { func TestParser2_1CanParsePackageSupplierNOASSERTIONTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -610,9 +611,9 @@ func TestParser2_1CanParsePackageSupplierNOASSERTIONTag(t *testing.T) { func TestParser2_1CanParsePackageOriginatorPersonTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -628,9 +629,9 @@ func TestParser2_1CanParsePackageOriginatorPersonTag(t *testing.T) { func TestParser2_1CanParsePackageOriginatorOrganizationTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -646,9 +647,9 @@ func TestParser2_1CanParsePackageOriginatorOrganizationTag(t *testing.T) { func TestParser2_1CanParsePackageOriginatorNOASSERTIONTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -664,9 +665,9 @@ func TestParser2_1CanParsePackageOriginatorNOASSERTIONTag(t *testing.T) { func TestParser2_1CanParsePackageVerificationCodeTagWithExcludes(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -689,9 +690,9 @@ func TestParser2_1CanParsePackageVerificationCodeTagWithExcludes(t *testing.T) { func TestParser2_1CanParsePackageVerificationCodeTagWithoutExcludes(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -712,9 +713,9 @@ func TestParser2_1CanParsePackageVerificationCodeTagWithoutExcludes(t *testing.T func TestPackageExternalRefPointerChangesAfterTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -757,9 +758,9 @@ func TestPackageExternalRefPointerChangesAfterTags(t *testing.T) { func TestParser2_1PackageCreatesRelationshipInDocument(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -777,9 +778,9 @@ func TestParser2_1PackageCreatesRelationshipInDocument(t *testing.T) { func TestParser2_1PackageCreatesAnnotationInDocument(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -797,9 +798,9 @@ func TestParser2_1PackageCreatesAnnotationInDocument(t *testing.T) { func TestParser2_1PackageUnknownTagFails(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_1.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -811,9 +812,9 @@ func TestParser2_1PackageUnknownTagFails(t *testing.T) { func TestParser2_1FailsIfInvalidSPDXIDInPackageSection(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{}, + pkg: &v2_1.Package{}, } // start with Package Name @@ -830,9 +831,9 @@ func TestParser2_1FailsIfInvalidSPDXIDInPackageSection(t *testing.T) { func TestParser2_1FailsIfInvalidPackageSupplierFormat(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{}, + pkg: &v2_1.Package{}, } // start with Package Name @@ -849,9 +850,9 @@ func TestParser2_1FailsIfInvalidPackageSupplierFormat(t *testing.T) { func TestParser2_1FailsIfUnknownPackageSupplierType(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{}, + pkg: &v2_1.Package{}, } // start with Package Name @@ -868,9 +869,9 @@ func TestParser2_1FailsIfUnknownPackageSupplierType(t *testing.T) { func TestParser2_1FailsIfInvalidPackageOriginatorFormat(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{}, + pkg: &v2_1.Package{}, } // start with Package Name @@ -887,9 +888,9 @@ func TestParser2_1FailsIfInvalidPackageOriginatorFormat(t *testing.T) { func TestParser2_1FailsIfUnknownPackageOriginatorType(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{}, + pkg: &v2_1.Package{}, } // start with Package Name @@ -906,9 +907,9 @@ func TestParser2_1FailsIfUnknownPackageOriginatorType(t *testing.T) { func TestParser2_1SetsFilesAnalyzedTagsCorrectly(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{}, + pkg: &v2_1.Package{}, } // start with Package Name @@ -931,9 +932,9 @@ func TestParser2_1SetsFilesAnalyzedTagsCorrectly(t *testing.T) { func TestParser2_1FailsIfInvalidPackageChecksumFormat(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{}, + pkg: &v2_1.Package{}, } // start with Package Name @@ -950,9 +951,9 @@ func TestParser2_1FailsIfInvalidPackageChecksumFormat(t *testing.T) { func TestParser2_1FailsIfInvalidPackageChecksumType(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{}, + pkg: &v2_1.Package{}, } // start with Package Name @@ -969,9 +970,9 @@ func TestParser2_1FailsIfInvalidPackageChecksumType(t *testing.T) { func TestParser2_1FailsIfInvalidExternalRefFormat(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{}, + pkg: &v2_1.Package{}, } // start with Package Name @@ -988,9 +989,9 @@ func TestParser2_1FailsIfInvalidExternalRefFormat(t *testing.T) { func TestParser2_1FailsIfExternalRefCommentBeforeExternalRef(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{}, + pkg: &v2_1.Package{}, } // start with Package Name @@ -1074,9 +1075,9 @@ func TestParser2_1PackageWithoutSpdxIdentifierThrowsError(t *testing.T) { // More than one package, the previous package doesn't contain the SPDXID pkgOldName := "p1" parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psPackage2_1, - pkg: &spdx.Package2_1{PackageName: pkgOldName}, + pkg: &v2_1.Package{PackageName: pkgOldName}, } pkgOld := parser.pkg parser.doc.Packages = append(parser.doc.Packages, pkgOld) diff --git a/tvloader/parser2v1/parse_relationship_test.go b/tvloader/parser2v1/parse_relationship_test.go index 3e5610f4..6d443886 100644 --- a/tvloader/parser2v1/parse_relationship_test.go +++ b/tvloader/parser2v1/parse_relationship_test.go @@ -4,13 +4,13 @@ package parser2v1 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Relationship section tests ===== func TestParser2_1FailsIfRelationshipNotSet(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } err := parser.parsePairForRelationship2_1("Relationship", "SPDXRef-A CONTAINS SPDXRef-B") @@ -21,7 +21,7 @@ func TestParser2_1FailsIfRelationshipNotSet(t *testing.T) { func TestParser2_1FailsIfRelationshipCommentWithoutRelationship(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } err := parser.parsePair2_1("RelationshipComment", "comment whatever") @@ -32,7 +32,7 @@ func TestParser2_1FailsIfRelationshipCommentWithoutRelationship(t *testing.T) { func TestParser2_1CanParseRelationshipTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -64,7 +64,7 @@ func TestParser2_1CanParseRelationshipTags(t *testing.T) { func TestParser2_1InvalidRelationshipTagsNoValueFail(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -78,7 +78,7 @@ func TestParser2_1InvalidRelationshipTagsNoValueFail(t *testing.T) { func TestParser2_1InvalidRelationshipTagsOneValueFail(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -92,7 +92,7 @@ func TestParser2_1InvalidRelationshipTagsOneValueFail(t *testing.T) { func TestParser2_1InvalidRelationshipTagsTwoValuesFail(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -106,7 +106,7 @@ func TestParser2_1InvalidRelationshipTagsTwoValuesFail(t *testing.T) { func TestParser2_1InvalidRelationshipTagsThreeValuesSucceed(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -120,7 +120,7 @@ func TestParser2_1InvalidRelationshipTagsThreeValuesSucceed(t *testing.T) { func TestParser2_1InvalidRelationshipTagsFourValuesFail(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -134,7 +134,7 @@ func TestParser2_1InvalidRelationshipTagsFourValuesFail(t *testing.T) { func TestParser2_1InvalidRelationshipTagsInvalidRefIDs(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } @@ -154,7 +154,7 @@ func TestParser2_1InvalidRelationshipTagsInvalidRefIDs(t *testing.T) { func TestParser2_1FailsToParseUnknownTagInRelationshipSection(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, } diff --git a/tvloader/parser2v1/parse_review.go b/tvloader/parser2v1/parse_review.go index 0d102d3b..b241a223 100644 --- a/tvloader/parser2v1/parse_review.go +++ b/tvloader/parser2v1/parse_review.go @@ -5,14 +5,14 @@ package parser2v1 import ( "fmt" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) func (parser *tvParser2_1) parsePairFromReview2_1(tag string, value string) error { switch tag { // tag for creating new review section case "Reviewer": - parser.rev = &spdx.Review2_1{} + parser.rev = &v2_1.Review{} parser.doc.Reviews = append(parser.doc.Reviews, parser.rev) subkey, subvalue, err := extractSubs(value) if err != nil { @@ -37,14 +37,14 @@ func (parser *tvParser2_1) parsePairFromReview2_1(tag string, value string) erro parser.rev.ReviewComment = value // for relationship tags, pass along but don't change state case "Relationship": - parser.rln = &spdx.Relationship2_1{} + parser.rln = &v2_1.Relationship{} parser.doc.Relationships = append(parser.doc.Relationships, parser.rln) return parser.parsePairForRelationship2_1(tag, value) case "RelationshipComment": return parser.parsePairForRelationship2_1(tag, value) // for annotation tags, pass along but don't change state case "Annotator": - parser.ann = &spdx.Annotation2_1{} + parser.ann = &v2_1.Annotation{} parser.doc.Annotations = append(parser.doc.Annotations, parser.ann) return parser.parsePairForAnnotation2_1(tag, value) case "AnnotationDate": diff --git a/tvloader/parser2v1/parse_review_test.go b/tvloader/parser2v1/parse_review_test.go index 2ef70067..c3cea2dd 100644 --- a/tvloader/parser2v1/parse_review_test.go +++ b/tvloader/parser2v1/parse_review_test.go @@ -4,7 +4,7 @@ package parser2v1 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Parser review section state change tests ===== @@ -12,15 +12,15 @@ func TestParser2_1ReviewStartsNewReviewAfterParsingReviewerTag(t *testing.T) { // create the first review rev1 := "John Doe" parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psReview2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_1{ + rev: &v2_1.Review{ Reviewer: rev1, ReviewerType: "Person", }, @@ -82,15 +82,15 @@ func TestParser2_1ReviewStartsNewReviewAfterParsingReviewerTag(t *testing.T) { func TestParser2_1ReviewStaysAfterParsingRelationshipTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psReview2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_1{ + rev: &v2_1.Review{ Reviewer: "Jane Doe", ReviewerType: "Person", }, @@ -129,15 +129,15 @@ func TestParser2_1ReviewStaysAfterParsingRelationshipTags(t *testing.T) { func TestParser2_1ReviewStaysAfterParsingAnnotationTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psReview2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_1{ + rev: &v2_1.Review{ Reviewer: "Jane Doe", ReviewerType: "Person", }, @@ -198,15 +198,15 @@ func TestParser2_1ReviewStaysAfterParsingAnnotationTags(t *testing.T) { func TestParser2_1ReviewFailsAfterParsingOtherSectionTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psReview2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_1{}, + rev: &v2_1.Review{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -235,15 +235,15 @@ func TestParser2_1ReviewFailsAfterParsingOtherSectionTags(t *testing.T) { // ===== Review data section tests ===== func TestParser2_1CanParseReviewTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psReview2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_1{}, + rev: &v2_1.Review{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -274,15 +274,15 @@ func TestParser2_1CanParseReviewTags(t *testing.T) { func TestParser2_1CanParseReviewerPersonTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psReview2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_1{}, + rev: &v2_1.Review{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -304,15 +304,15 @@ func TestParser2_1CanParseReviewerPersonTag(t *testing.T) { func TestParser2_1CanParseReviewerOrganizationTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psReview2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_1{}, + rev: &v2_1.Review{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -334,15 +334,15 @@ func TestParser2_1CanParseReviewerOrganizationTag(t *testing.T) { func TestParser2_1CanParseReviewerToolTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psReview2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_1{}, + rev: &v2_1.Review{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -364,9 +364,9 @@ func TestParser2_1CanParseReviewerToolTag(t *testing.T) { func TestParser2_1FailsIfReviewerInvalidFormat(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psReview2_1, - rev: &spdx.Review2_1{}, + rev: &v2_1.Review{}, } parser.doc.Reviews = append(parser.doc.Reviews, parser.rev) @@ -378,9 +378,9 @@ func TestParser2_1FailsIfReviewerInvalidFormat(t *testing.T) { func TestParser2_1FailsIfReviewerUnknownType(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psReview2_1, - rev: &spdx.Review2_1{}, + rev: &v2_1.Review{}, } parser.doc.Reviews = append(parser.doc.Reviews, parser.rev) @@ -392,15 +392,15 @@ func TestParser2_1FailsIfReviewerUnknownType(t *testing.T) { func TestParser2_1ReviewUnknownTagFails(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psReview2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_1{ + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_1{}, + rev: &v2_1.Review{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) diff --git a/tvloader/parser2v1/parse_snippet.go b/tvloader/parser2v1/parse_snippet.go index 33392d56..ad4c74f0 100644 --- a/tvloader/parser2v1/parse_snippet.go +++ b/tvloader/parser2v1/parse_snippet.go @@ -6,7 +6,8 @@ import ( "fmt" "strconv" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) func (parser *tvParser2_1) parsePairFromSnippet2_1(tag string, value string) error { @@ -17,7 +18,7 @@ func (parser *tvParser2_1) parsePairFromSnippet2_1(tag string, value string) err if parser.file != nil && parser.file.FileSPDXIdentifier == nullSpdxElementId2_1 { return fmt.Errorf("file with FileName %s does not have SPDX identifier", parser.file.FileName) } - parser.snippet = &spdx.Snippet2_1{} + parser.snippet = &v2_1.Snippet{} eID, err := extractElementID(value) if err != nil { return err @@ -25,7 +26,7 @@ func (parser *tvParser2_1) parsePairFromSnippet2_1(tag string, value string) err // FIXME: how should we handle where not associated with current file? if parser.file != nil { if parser.file.Snippets == nil { - parser.file.Snippets = map[spdx.ElementID]*spdx.Snippet2_1{} + parser.file.Snippets = map[common.ElementID]*v2_1.Snippet{} } parser.file.Snippets[eID] = parser.snippet } @@ -67,9 +68,9 @@ func (parser *tvParser2_1) parsePairFromSnippet2_1(tag string, value string) err } if parser.snippet.Ranges == nil { - parser.snippet.Ranges = []spdx.SnippetRange{} + parser.snippet.Ranges = []common.SnippetRange{} } - byteRange := spdx.SnippetRange{StartPointer: spdx.SnippetRangePointer{Offset: bIntStart}, EndPointer: spdx.SnippetRangePointer{Offset: bIntEnd}} + byteRange := common.SnippetRange{StartPointer: common.SnippetRangePointer{Offset: bIntStart}, EndPointer: common.SnippetRangePointer{Offset: bIntEnd}} parser.snippet.Ranges = append(parser.snippet.Ranges, byteRange) case "SnippetLineRange": lineStart, lineEnd, err := extractSubs(value) @@ -86,9 +87,9 @@ func (parser *tvParser2_1) parsePairFromSnippet2_1(tag string, value string) err } if parser.snippet.Ranges == nil { - parser.snippet.Ranges = []spdx.SnippetRange{} + parser.snippet.Ranges = []common.SnippetRange{} } - lineRange := spdx.SnippetRange{StartPointer: spdx.SnippetRangePointer{LineNumber: lInttStart}, EndPointer: spdx.SnippetRangePointer{LineNumber: lInttEnd}} + lineRange := common.SnippetRange{StartPointer: common.SnippetRangePointer{LineNumber: lInttStart}, EndPointer: common.SnippetRangePointer{LineNumber: lInttEnd}} parser.snippet.Ranges = append(parser.snippet.Ranges, lineRange) case "SnippetLicenseConcluded": parser.snippet.SnippetLicenseConcluded = value @@ -104,14 +105,14 @@ func (parser *tvParser2_1) parsePairFromSnippet2_1(tag string, value string) err parser.snippet.SnippetName = value // for relationship tags, pass along but don't change state case "Relationship": - parser.rln = &spdx.Relationship2_1{} + parser.rln = &v2_1.Relationship{} parser.doc.Relationships = append(parser.doc.Relationships, parser.rln) return parser.parsePairForRelationship2_1(tag, value) case "RelationshipComment": return parser.parsePairForRelationship2_1(tag, value) // for annotation tags, pass along but don't change state case "Annotator": - parser.ann = &spdx.Annotation2_1{} + parser.ann = &v2_1.Annotation{} parser.doc.Annotations = append(parser.doc.Annotations, parser.ann) return parser.parsePairForAnnotation2_1(tag, value) case "AnnotationDate": diff --git a/tvloader/parser2v1/parse_snippet_test.go b/tvloader/parser2v1/parse_snippet_test.go index ea747f48..aa42c3c3 100644 --- a/tvloader/parser2v1/parse_snippet_test.go +++ b/tvloader/parser2v1/parse_snippet_test.go @@ -4,19 +4,20 @@ package parser2v1 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Parser snippet section state change tests ===== func TestParser2_1SnippetStartsNewSnippetAfterParsingSnippetSPDXIDTag(t *testing.T) { // create the first snippet - sid1 := spdx.ElementID("s1") + sid1 := common.ElementID("s1") parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{SnippetSPDXIdentifier: sid1}, + pkg: &v2_1.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{SnippetSPDXIdentifier: sid1}, } s1 := parser.snippet parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -71,11 +72,11 @@ func TestParser2_1SnippetStartsNewSnippetAfterParsingSnippetSPDXIDTag(t *testing func TestParser2_1SnippetStartsNewPackageAfterParsingPackageNameTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_1.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{SnippetSPDXIdentifier: "s1"}, } p1 := parser.pkg f1 := parser.file @@ -146,11 +147,11 @@ func TestParser2_1SnippetStartsNewPackageAfterParsingPackageNameTag(t *testing.T func TestParser2_1SnippetMovesToFileAfterParsingFileNameTag(t *testing.T) { f1Name := "f1.txt" parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_1.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{SnippetSPDXIdentifier: "s1"}, } p1 := parser.pkg f1 := parser.file @@ -198,11 +199,11 @@ func TestParser2_1SnippetMovesToFileAfterParsingFileNameTag(t *testing.T) { func TestParser2_1SnippetMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_1.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{SnippetSPDXIdentifier: "s1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -219,11 +220,11 @@ func TestParser2_1SnippetMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing. func TestParser2_1SnippetMovesToReviewAfterParsingReviewerTag(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_1.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{SnippetSPDXIdentifier: "s1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -240,11 +241,11 @@ func TestParser2_1SnippetMovesToReviewAfterParsingReviewerTag(t *testing.T) { func TestParser2_1SnippetStaysAfterParsingRelationshipTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_1.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{SnippetSPDXIdentifier: "s1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -279,11 +280,11 @@ func TestParser2_1SnippetStaysAfterParsingRelationshipTags(t *testing.T) { func TestParser2_1SnippetStaysAfterParsingAnnotationTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_1.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{SnippetSPDXIdentifier: "s1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -341,11 +342,11 @@ func TestParser2_1SnippetStaysAfterParsingAnnotationTags(t *testing.T) { // ===== Snippet data section tests ===== func TestParser2_1CanParseSnippetTags(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{}, + pkg: &v2_1.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -364,7 +365,7 @@ func TestParser2_1CanParseSnippetTags(t *testing.T) { if err != nil { t.Errorf("expected nil error, got %v", err) } - wantDeID := spdx.DocElementID{DocumentRefID: "", ElementRefID: spdx.ElementID("f1")} + wantDeID := common.DocElementID{DocumentRefID: "", ElementRefID: common.ElementID("f1")} if parser.snippet.SnippetFromFileSPDXIdentifier != wantDeID.ElementRefID { t.Errorf("got %v for SnippetFromFileSPDXIdentifier", parser.snippet.SnippetFromFileSPDXIdentifier) } @@ -469,11 +470,11 @@ func TestParser2_1CanParseSnippetTags(t *testing.T) { func TestParser2_1SnippetUnknownTagFails(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_1.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{SnippetSPDXIdentifier: "s1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -486,11 +487,11 @@ func TestParser2_1SnippetUnknownTagFails(t *testing.T) { func TestParser2_1FailsForInvalidSnippetSPDXID(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{}, + pkg: &v2_1.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -504,11 +505,11 @@ func TestParser2_1FailsForInvalidSnippetSPDXID(t *testing.T) { func TestParser2_1FailsForInvalidSnippetFromFileSPDXID(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{}, + pkg: &v2_1.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -527,11 +528,11 @@ func TestParser2_1FailsForInvalidSnippetFromFileSPDXID(t *testing.T) { func TestParser2_1FailsForInvalidSnippetByteValues(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{}, + pkg: &v2_1.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -558,11 +559,11 @@ func TestParser2_1FailsForInvalidSnippetByteValues(t *testing.T) { func TestParser2_1FailsForInvalidSnippetLineValues(t *testing.T) { parser := tvParser2_1{ - doc: &spdx.Document2_1{Packages: []*spdx.Package2_1{}}, + doc: &v2_1.Document{Packages: []*v2_1.Package{}}, st: psSnippet2_1, - pkg: &spdx.Package2_1{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_1{}}, - file: &spdx.File2_1{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_1{}}, - snippet: &spdx.Snippet2_1{}, + pkg: &v2_1.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_1.File{}}, + file: &v2_1.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_1.Snippet{}}, + snippet: &v2_1.Snippet{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -592,11 +593,11 @@ func TestParser2_1FilesWithoutSpdxIdThrowErrorWithSnippets(t *testing.T) { // Last unpackaged file before the snippet starts // Last file of a package and new snippet starts fileName := "f2.txt" - sid1 := spdx.ElementID("s1") + sid1 := common.ElementID("s1") parser2 := tvParser2_1{ - doc: &spdx.Document2_1{}, + doc: &v2_1.Document{}, st: psCreationInfo2_1, - file: &spdx.File2_1{FileName: fileName}, + file: &v2_1.File{FileName: fileName}, } err := parser2.parsePair2_1("SnippetSPDXID", string(sid1)) if err == nil { diff --git a/tvloader/parser2v1/parser.go b/tvloader/parser2v1/parser.go index 70f4819c..c083fc9b 100644 --- a/tvloader/parser2v1/parser.go +++ b/tvloader/parser2v1/parser.go @@ -6,13 +6,14 @@ package parser2v1 import ( "fmt" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" "github.com/spdx/tools-golang/tvloader/reader" ) // ParseTagValues takes a list of (tag, value) pairs, parses it and returns // a pointer to a parsed SPDX Document. -func ParseTagValues(tvs []reader.TagValuePair) (*spdx.Document2_1, error) { +func ParseTagValues(tvs []reader.TagValuePair) (*v2_1.Document, error) { parser := tvParser2_1{} for _, tv := range tvs { err := parser.parsePair2_1(tv.Tag, tv.Value) @@ -59,8 +60,8 @@ func (parser *tvParser2_1) parsePairFromStart2_1(tag string, value string) error // create an SPDX Document data struct if we don't have one already if parser.doc == nil { - parser.doc = &spdx.Document2_1{ - ExternalDocumentReferences: []spdx.ExternalDocumentRef2_1{}, + parser.doc = &v2_1.Document{ + ExternalDocumentReferences: []v2_1.ExternalDocumentRef{}, } } @@ -84,10 +85,10 @@ func (parser *tvParser2_1) parsePairFromStart2_1(tag string, value string) error if err != nil { return err } - edr := spdx.ExternalDocumentRef2_1{ + edr := v2_1.ExternalDocumentRef{ DocumentRefID: documentRefID, URI: uri, - Checksum: spdx.Checksum{Algorithm: spdx.ChecksumAlgorithm(alg), Value: checksum}, + Checksum: common.Checksum{Algorithm: common.ChecksumAlgorithm(alg), Value: checksum}, } parser.doc.ExternalDocumentReferences = append(parser.doc.ExternalDocumentReferences, edr) case "DocumentComment": diff --git a/tvloader/parser2v1/types.go b/tvloader/parser2v1/types.go index 164f6a89..8f3cf238 100644 --- a/tvloader/parser2v1/types.go +++ b/tvloader/parser2v1/types.go @@ -3,26 +3,27 @@ package parser2v1 import ( - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) type tvParser2_1 struct { // document into which data is being parsed - doc *spdx.Document2_1 + doc *v2_1.Document // current parser state st tvParserState2_1 // current SPDX item being filled in, if any - pkg *spdx.Package2_1 - pkgExtRef *spdx.PackageExternalReference2_1 - file *spdx.File2_1 - fileAOP *spdx.ArtifactOfProject2_1 - snippet *spdx.Snippet2_1 - otherLic *spdx.OtherLicense2_1 - rln *spdx.Relationship2_1 - ann *spdx.Annotation2_1 - rev *spdx.Review2_1 + pkg *v2_1.Package + pkgExtRef *v2_1.PackageExternalReference + file *v2_1.File + fileAOP *v2_1.ArtifactOfProject + snippet *v2_1.Snippet + otherLic *v2_1.OtherLicense + rln *v2_1.Relationship + ann *v2_1.Annotation + rev *v2_1.Review // don't need creation info pointer b/c only one, // and we can get to it via doc.CreationInfo } @@ -53,4 +54,4 @@ const ( psReview2_1 ) -const nullSpdxElementId2_1 = spdx.ElementID("") +const nullSpdxElementId2_1 = common.ElementID("") diff --git a/tvloader/parser2v1/util.go b/tvloader/parser2v1/util.go index d2df57b1..7cac43d6 100644 --- a/tvloader/parser2v1/util.go +++ b/tvloader/parser2v1/util.go @@ -6,7 +6,7 @@ import ( "fmt" "strings" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" ) // used to extract key / value from embedded substrings @@ -26,7 +26,7 @@ func extractSubs(value string) (string, string, error) { // used to extract DocumentRef and SPDXRef values from an SPDX Identifier // which can point either to this document or to a different one -func extractDocElementID(value string) (spdx.DocElementID, error) { +func extractDocElementID(value string) (common.DocElementID, error) { docRefID := "" idStr := value @@ -36,16 +36,16 @@ func extractDocElementID(value string) (spdx.DocElementID, error) { strs := strings.Split(idStr, ":") // should be exactly two, part before and part after if len(strs) < 2 { - return spdx.DocElementID{}, fmt.Errorf("no colon found although DocumentRef- prefix present") + return common.DocElementID{}, fmt.Errorf("no colon found although DocumentRef- prefix present") } if len(strs) > 2 { - return spdx.DocElementID{}, fmt.Errorf("more than one colon found") + return common.DocElementID{}, fmt.Errorf("more than one colon found") } // trim the prefix and confirm non-empty docRefID = strings.TrimPrefix(strs[0], "DocumentRef-") if docRefID == "" { - return spdx.DocElementID{}, fmt.Errorf("document identifier has nothing after prefix") + return common.DocElementID{}, fmt.Errorf("document identifier has nothing after prefix") } // and use remainder for element ID parsing idStr = strs[1] @@ -53,46 +53,46 @@ func extractDocElementID(value string) (spdx.DocElementID, error) { // check prefix to confirm it's got the right prefix for element IDs if !strings.HasPrefix(idStr, "SPDXRef-") { - return spdx.DocElementID{}, fmt.Errorf("missing SPDXRef- prefix for element identifier") + return common.DocElementID{}, fmt.Errorf("missing SPDXRef- prefix for element identifier") } // make sure no colons are present if strings.Contains(idStr, ":") { // we know this means there was no DocumentRef- prefix, because // we would have handled multiple colons above if it was - return spdx.DocElementID{}, fmt.Errorf("invalid colon in element identifier") + return common.DocElementID{}, fmt.Errorf("invalid colon in element identifier") } // trim the prefix and confirm non-empty eltRefID := strings.TrimPrefix(idStr, "SPDXRef-") if eltRefID == "" { - return spdx.DocElementID{}, fmt.Errorf("element identifier has nothing after prefix") + return common.DocElementID{}, fmt.Errorf("element identifier has nothing after prefix") } // we're good - return spdx.DocElementID{DocumentRefID: docRefID, ElementRefID: spdx.ElementID(eltRefID)}, nil + return common.DocElementID{DocumentRefID: docRefID, ElementRefID: common.ElementID(eltRefID)}, nil } // used to extract SPDXRef values only from an SPDX Identifier which can point // to this document only. Use extractDocElementID for parsing IDs that can // refer either to this document or a different one. -func extractElementID(value string) (spdx.ElementID, error) { +func extractElementID(value string) (common.ElementID, error) { // check prefix to confirm it's got the right prefix for element IDs if !strings.HasPrefix(value, "SPDXRef-") { - return spdx.ElementID(""), fmt.Errorf("missing SPDXRef- prefix for element identifier") + return common.ElementID(""), fmt.Errorf("missing SPDXRef- prefix for element identifier") } // make sure no colons are present if strings.Contains(value, ":") { - return spdx.ElementID(""), fmt.Errorf("invalid colon in element identifier") + return common.ElementID(""), fmt.Errorf("invalid colon in element identifier") } // trim the prefix and confirm non-empty eltRefID := strings.TrimPrefix(value, "SPDXRef-") if eltRefID == "" { - return spdx.ElementID(""), fmt.Errorf("element identifier has nothing after prefix") + return common.ElementID(""), fmt.Errorf("element identifier has nothing after prefix") } // we're good - return spdx.ElementID(eltRefID), nil + return common.ElementID(eltRefID), nil } diff --git a/tvloader/parser2v1/util_test.go b/tvloader/parser2v1/util_test.go index 79afc1e8..349d84fd 100644 --- a/tvloader/parser2v1/util_test.go +++ b/tvloader/parser2v1/util_test.go @@ -4,7 +4,7 @@ package parser2v1 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" ) // ===== Helper function tests ===== @@ -65,7 +65,7 @@ func helperForExtractDocElementID(t *testing.T, tst string, wantErr bool, wantDo t.Errorf("testing %v: want %v for DocumentRefID, got %v", tst, wantDoc, deID.DocumentRefID) } } - if deID.ElementRefID != spdx.ElementID(wantElt) { + if deID.ElementRefID != common.ElementID(wantElt) { if wantElt == "" { t.Errorf("testing %v: want emptyString for ElementRefID, got %v", tst, deID.ElementRefID) } else { @@ -101,7 +101,7 @@ func helperForExtractElementID(t *testing.T, tst string, wantErr bool, wantElt s if err == nil && wantErr == true { t.Errorf("testing %v: expected non-nil error, got nil", tst) } - if eID != spdx.ElementID(wantElt) { + if eID != common.ElementID(wantElt) { if wantElt == "" { t.Errorf("testing %v: want emptyString for ElementRefID, got %v", tst, eID) } else { diff --git a/tvloader/parser2v2/parse_annotation_test.go b/tvloader/parser2v2/parse_annotation_test.go index cdd05415..c2ba4875 100644 --- a/tvloader/parser2v2/parse_annotation_test.go +++ b/tvloader/parser2v2/parse_annotation_test.go @@ -4,13 +4,13 @@ package parser2v2 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Annotation section tests ===== func TestParser2_2FailsIfAnnotationNotSet(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } err := parser.parsePairForAnnotation2_2("Annotator", "Person: John Doe (jdoe@example.com)") @@ -21,7 +21,7 @@ func TestParser2_2FailsIfAnnotationNotSet(t *testing.T) { func TestParser2_2FailsIfAnnotationTagUnknown(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } // start with valid annotator @@ -38,7 +38,7 @@ func TestParser2_2FailsIfAnnotationTagUnknown(t *testing.T) { func TestParser2_2FailsIfAnnotationFieldsWithoutAnnotation(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } err := parser.parsePair2_2("AnnotationDate", "2018-09-15T17:25:00Z") @@ -61,7 +61,7 @@ func TestParser2_2FailsIfAnnotationFieldsWithoutAnnotation(t *testing.T) { func TestParser2_2CanParseAnnotationTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -121,7 +121,7 @@ func TestParser2_2CanParseAnnotationTags(t *testing.T) { func TestParser2_2FailsIfAnnotatorInvalid(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } err := parser.parsePair2_2("Annotator", "John Doe (jdoe@example.com)") @@ -132,7 +132,7 @@ func TestParser2_2FailsIfAnnotatorInvalid(t *testing.T) { func TestParser2_2FailsIfAnnotatorTypeInvalid(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } err := parser.parsePair2_2("Annotator", "Human: John Doe (jdoe@example.com)") @@ -143,7 +143,7 @@ func TestParser2_2FailsIfAnnotatorTypeInvalid(t *testing.T) { func TestParser2_2FailsIfAnnotationRefInvalid(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } // start with valid annotator diff --git a/tvloader/parser2v2/parse_creation_info.go b/tvloader/parser2v2/parse_creation_info.go index f8406fc5..da258bdf 100644 --- a/tvloader/parser2v2/parse_creation_info.go +++ b/tvloader/parser2v2/parse_creation_info.go @@ -6,7 +6,8 @@ import ( "fmt" "strings" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) func (parser *tvParser2_2) parsePairFromCreationInfo2_2(tag string, value string) error { @@ -17,7 +18,7 @@ func (parser *tvParser2_2) parsePairFromCreationInfo2_2(tag string, value string // create an SPDX Creation Info data struct if we don't have one already if parser.doc.CreationInfo == nil { - parser.doc.CreationInfo = &spdx.CreationInfo2_2{} + parser.doc.CreationInfo = &v2_2.CreationInfo{} } ci := parser.doc.CreationInfo @@ -30,7 +31,7 @@ func (parser *tvParser2_2) parsePairFromCreationInfo2_2(tag string, value string return err } - creator := spdx.Creator{Creator: subvalue} + creator := common.Creator{Creator: subvalue} switch subkey { case "Person", "Organization", "Tool": creator.CreatorType = subkey @@ -54,7 +55,7 @@ func (parser *tvParser2_2) parsePairFromCreationInfo2_2(tag string, value string return fmt.Errorf("file with FileName %s does not have SPDX identifier", parser.file.FileName) } parser.st = psPackage2_2 - parser.pkg = &spdx.Package2_2{ + parser.pkg = &v2_2.Package{ FilesAnalyzed: true, IsFilesAnalyzedTagPresent: false, } @@ -75,14 +76,14 @@ func (parser *tvParser2_2) parsePairFromCreationInfo2_2(tag string, value string return parser.parsePairFromReview2_2(tag, value) // for relationship tags, pass along but don't change state case "Relationship": - parser.rln = &spdx.Relationship2_2{} + parser.rln = &v2_2.Relationship{} parser.doc.Relationships = append(parser.doc.Relationships, parser.rln) return parser.parsePairForRelationship2_2(tag, value) case "RelationshipComment": return parser.parsePairForRelationship2_2(tag, value) // for annotation tags, pass along but don't change state case "Annotator": - parser.ann = &spdx.Annotation2_2{} + parser.ann = &v2_2.Annotation{} parser.doc.Annotations = append(parser.doc.Annotations, parser.ann) return parser.parsePairForAnnotation2_2(tag, value) case "AnnotationDate": diff --git a/tvloader/parser2v2/parse_creation_info_test.go b/tvloader/parser2v2/parse_creation_info_test.go index 71213460..dcf60986 100644 --- a/tvloader/parser2v2/parse_creation_info_test.go +++ b/tvloader/parser2v2/parse_creation_info_test.go @@ -4,13 +4,13 @@ package parser2v2 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Parser creation info state change tests ===== func TestParser2_2CIMovesToPackageAfterParsingPackageNameTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } pkgName := "testPkg" @@ -46,7 +46,7 @@ func TestParser2_2CIMovesToPackageAfterParsingPackageNameTag(t *testing.T) { func TestParser2_2CIMovesToFileAfterParsingFileNameTagWithNoPackages(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } err := parser.parsePair2_2("FileName", "testFile") @@ -66,7 +66,7 @@ func TestParser2_2CIMovesToFileAfterParsingFileNameTagWithNoPackages(t *testing. func TestParser2_2CIMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } err := parser.parsePair2_2("LicenseID", "LicenseRef-TestLic") @@ -80,7 +80,7 @@ func TestParser2_2CIMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing.T) { func TestParser2_2CIMovesToReviewAfterParsingReviewerTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } err := parser.parsePair2_2("Reviewer", "Person: John Doe") @@ -94,7 +94,7 @@ func TestParser2_2CIMovesToReviewAfterParsingReviewerTag(t *testing.T) { func TestParser2_2CIStaysAfterParsingRelationshipTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -117,7 +117,7 @@ func TestParser2_2CIStaysAfterParsingRelationshipTags(t *testing.T) { func TestParser2_2CIStaysAfterParsingAnnotationTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -164,7 +164,7 @@ func TestParser2_2CIStaysAfterParsingAnnotationTags(t *testing.T) { func TestParser2_2FailsParsingCreationInfoWithInvalidState(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psPackage2_2, } err := parser.parsePairFromCreationInfo2_2("SPDXVersion", "SPDX-2.2") @@ -176,7 +176,7 @@ func TestParser2_2FailsParsingCreationInfoWithInvalidState(t *testing.T) { // ===== Creation Info section tests ===== func TestParser2_2HasCreationInfoAfterCallToParseFirstTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } err := parser.parsePairFromCreationInfo2_2("LicenseListVersion", "3.9") @@ -190,7 +190,7 @@ func TestParser2_2HasCreationInfoAfterCallToParseFirstTag(t *testing.T) { func TestParser2_2CanParseCreationInfoTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -281,7 +281,7 @@ func TestParser2_2CanParseCreationInfoTags(t *testing.T) { func TestParser2_2InvalidCreatorTagsFail(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -298,7 +298,7 @@ func TestParser2_2InvalidCreatorTagsFail(t *testing.T) { func TestParser2_2CreatorTagWithMultipleColonsPasses(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -310,7 +310,7 @@ func TestParser2_2CreatorTagWithMultipleColonsPasses(t *testing.T) { func TestParser2_2CIUnknownTagFails(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -322,7 +322,7 @@ func TestParser2_2CIUnknownTagFails(t *testing.T) { func TestParser2_2CICreatesRelationship(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -340,7 +340,7 @@ func TestParser2_2CICreatesRelationship(t *testing.T) { func TestParser2_2CICreatesAnnotation(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } diff --git a/tvloader/parser2v2/parse_file.go b/tvloader/parser2v2/parse_file.go index e564147a..96cefce5 100644 --- a/tvloader/parser2v2/parse_file.go +++ b/tvloader/parser2v2/parse_file.go @@ -5,7 +5,8 @@ package parser2v2 import ( "fmt" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) func (parser *tvParser2_2) parsePairFromFile2_2(tag string, value string) error { @@ -22,7 +23,7 @@ func (parser *tvParser2_2) parsePairFromFile2_2(tag string, value string) error if parser.file != nil && parser.file.FileSPDXIdentifier == nullSpdxElementId2_2 { return fmt.Errorf("file with FileName %s does not have SPDX identifier", parser.file.FileName) } - parser.file = &spdx.File2_2{} + parser.file = &v2_2.File{} parser.file.FileName = value // tag for creating new package section and going back to parsing Package case "PackageName": @@ -50,12 +51,12 @@ func (parser *tvParser2_2) parsePairFromFile2_2(tag string, value string) error parser.file.FileSPDXIdentifier = eID if parser.pkg == nil { if parser.doc.Files == nil { - parser.doc.Files = []*spdx.File2_2{} + parser.doc.Files = []*v2_2.File{} } parser.doc.Files = append(parser.doc.Files, parser.file) } else { if parser.pkg.Files == nil { - parser.pkg.Files = []*spdx.File2_2{} + parser.pkg.Files = []*v2_2.File{} } parser.pkg.Files = append(parser.pkg.Files, parser.file) } @@ -67,12 +68,12 @@ func (parser *tvParser2_2) parsePairFromFile2_2(tag string, value string) error return err } if parser.file.Checksums == nil { - parser.file.Checksums = []spdx.Checksum{} + parser.file.Checksums = []common.Checksum{} } - switch spdx.ChecksumAlgorithm(subkey) { - case spdx.SHA1, spdx.SHA256, spdx.MD5: - algorithm := spdx.ChecksumAlgorithm(subkey) - parser.file.Checksums = append(parser.file.Checksums, spdx.Checksum{Algorithm: algorithm, Value: subvalue}) + switch common.ChecksumAlgorithm(subkey) { + case common.SHA1, common.SHA256, common.MD5: + algorithm := common.ChecksumAlgorithm(subkey) + parser.file.Checksums = append(parser.file.Checksums, common.Checksum{Algorithm: algorithm, Value: subvalue}) default: return fmt.Errorf("got unknown checksum type %s", subkey) } @@ -85,7 +86,7 @@ func (parser *tvParser2_2) parsePairFromFile2_2(tag string, value string) error case "FileCopyrightText": parser.file.FileCopyrightText = value case "ArtifactOfProjectName": - parser.fileAOP = &spdx.ArtifactOfProject2_2{} + parser.fileAOP = &v2_2.ArtifactOfProject{} parser.file.ArtifactOfProjects = append(parser.file.ArtifactOfProjects, parser.fileAOP) parser.fileAOP.Name = value case "ArtifactOfProjectHomePage": @@ -110,14 +111,14 @@ func (parser *tvParser2_2) parsePairFromFile2_2(tag string, value string) error parser.file.FileAttributionTexts = append(parser.file.FileAttributionTexts, value) // for relationship tags, pass along but don't change state case "Relationship": - parser.rln = &spdx.Relationship2_2{} + parser.rln = &v2_2.Relationship{} parser.doc.Relationships = append(parser.doc.Relationships, parser.rln) return parser.parsePairForRelationship2_2(tag, value) case "RelationshipComment": return parser.parsePairForRelationship2_2(tag, value) // for annotation tags, pass along but don't change state case "Annotator": - parser.ann = &spdx.Annotation2_2{} + parser.ann = &v2_2.Annotation{} parser.doc.Annotations = append(parser.doc.Annotations, parser.ann) return parser.parsePairForAnnotation2_2(tag, value) case "AnnotationDate": diff --git a/tvloader/parser2v2/parse_file_test.go b/tvloader/parser2v2/parse_file_test.go index 30f9f5e7..7341d9e2 100644 --- a/tvloader/parser2v2/parse_file_test.go +++ b/tvloader/parser2v2/parse_file_test.go @@ -4,7 +4,8 @@ package parser2v2 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Parser file section state change tests ===== @@ -13,10 +14,10 @@ func TestParser2_2FileStartsNewFileAfterParsingFileNameTag(t *testing.T) { fileOldName := "f1.txt" parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: fileOldName, FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: fileOldName, FileSPDXIdentifier: "f1"}, } fileOld := parser.file parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -88,7 +89,7 @@ func TestParser2_2FileStartsNewFileAfterParsingFileNameTag(t *testing.T) { func TestParser2_2FileAddsToPackageOrUnpackagedFiles(t *testing.T) { // start with no packages parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -149,10 +150,10 @@ func TestParser2_2FileStartsNewPackageAfterParsingPackageNameTag(t *testing.T) { f1Name := "f1.txt" parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: p1Name, PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: f1Name, FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: p1Name, PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: f1Name, FileSPDXIdentifier: "f1"}, } p1 := parser.pkg f1 := parser.file @@ -217,10 +218,10 @@ func TestParser2_2FileStartsNewPackageAfterParsingPackageNameTag(t *testing.T) { func TestParser2_2FileMovesToSnippetAfterParsingSnippetSPDXIDTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -242,10 +243,10 @@ func TestParser2_2FileMovesToSnippetAfterParsingSnippetSPDXIDTag(t *testing.T) { func TestParser2_2FileMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -261,10 +262,10 @@ func TestParser2_2FileMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing.T) func TestParser2_2FileMovesToReviewAfterParsingReviewerTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -280,10 +281,10 @@ func TestParser2_2FileMovesToReviewAfterParsingReviewerTag(t *testing.T) { func TestParser2_2FileStaysAfterParsingRelationshipTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -309,10 +310,10 @@ func TestParser2_2FileStaysAfterParsingRelationshipTags(t *testing.T) { func TestParser2_2FileStaysAfterParsingAnnotationTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -361,9 +362,9 @@ func TestParser2_2FileStaysAfterParsingAnnotationTags(t *testing.T) { // ===== File data section tests ===== func TestParser2_2CanParseFileTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -445,15 +446,15 @@ func TestParser2_2CanParseFileTags(t *testing.T) { } for _, checksum := range parser.file.Checksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != codeSha1 { t.Errorf("expected %s for FileChecksumSHA1, got %s", codeSha1, checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != codeSha256 { t.Errorf("expected %s for FileChecksumSHA1, got %s", codeSha256, checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != codeMd5 { t.Errorf("expected %s for FileChecksumSHA1, got %s", codeMd5, checksum.Value) } @@ -703,10 +704,10 @@ func TestParser2_2CanParseFileTags(t *testing.T) { func TestParser2_2FileCreatesRelationshipInDocument(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -725,10 +726,10 @@ func TestParser2_2FileCreatesRelationshipInDocument(t *testing.T) { func TestParser2_2FileCreatesAnnotationInDocument(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -747,10 +748,10 @@ func TestParser2_2FileCreatesAnnotationInDocument(t *testing.T) { func TestParser2_2FileUnknownTagFails(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -763,10 +764,10 @@ func TestParser2_2FileUnknownTagFails(t *testing.T) { func TestFileAOPPointerChangesAfterTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -820,9 +821,9 @@ func TestFileAOPPointerChangesAfterTags(t *testing.T) { func TestParser2_2FailsIfInvalidSPDXIDInFileSection(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -840,9 +841,9 @@ func TestParser2_2FailsIfInvalidSPDXIDInFileSection(t *testing.T) { func TestParser2_2FailsIfInvalidChecksumFormatInFileSection(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -860,9 +861,9 @@ func TestParser2_2FailsIfInvalidChecksumFormatInFileSection(t *testing.T) { func TestParser2_1FailsIfUnknownChecksumTypeInFileSection(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -880,9 +881,9 @@ func TestParser2_1FailsIfUnknownChecksumTypeInFileSection(t *testing.T) { func TestParser2_2FailsIfArtifactHomePageBeforeArtifactName(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -900,9 +901,9 @@ func TestParser2_2FailsIfArtifactHomePageBeforeArtifactName(t *testing.T) { func TestParser2_2FailsIfArtifactURIBeforeArtifactName(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -921,9 +922,9 @@ func TestParser2_2FailsIfArtifactURIBeforeArtifactName(t *testing.T) { func TestParser2_2FilesWithoutSpdxIdThrowError(t *testing.T) { // case 1: The previous file (packaged or unpackaged) does not contain spdx ID parser1 := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, - file: &spdx.File2_2{FileName: "FileName"}, + file: &v2_2.File{FileName: "FileName"}, } err := parser1.parsePair2_2("FileName", "f2") @@ -934,11 +935,11 @@ func TestParser2_2FilesWithoutSpdxIdThrowError(t *testing.T) { // case 2: Invalid file with snippet // Last unpackaged file before the snippet start fileName := "f2.txt" - sid1 := spdx.ElementID("s1") + sid1 := common.ElementID("s1") parser2 := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, - file: &spdx.File2_2{FileName: fileName}, + file: &v2_2.File{FileName: fileName}, } err = parser2.parsePair2_2("SnippetSPDXID", string(sid1)) if err == nil { @@ -949,7 +950,7 @@ func TestParser2_2FilesWithoutSpdxIdThrowError(t *testing.T) { // Last unpackaged file before the package starts // Last file of a package and New package starts parser3 := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } fileName = "f3.txt" diff --git a/tvloader/parser2v2/parse_other_license.go b/tvloader/parser2v2/parse_other_license.go index 371f8348..95250a60 100644 --- a/tvloader/parser2v2/parse_other_license.go +++ b/tvloader/parser2v2/parse_other_license.go @@ -5,14 +5,14 @@ package parser2v2 import ( "fmt" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) func (parser *tvParser2_2) parsePairFromOtherLicense2_2(tag string, value string) error { switch tag { // tag for creating new other license section case "LicenseID": - parser.otherLic = &spdx.OtherLicense2_2{} + parser.otherLic = &v2_2.OtherLicense{} parser.doc.OtherLicenses = append(parser.doc.OtherLicenses, parser.otherLic) parser.otherLic.LicenseIdentifier = value case "ExtractedText": @@ -25,14 +25,14 @@ func (parser *tvParser2_2) parsePairFromOtherLicense2_2(tag string, value string parser.otherLic.LicenseComment = value // for relationship tags, pass along but don't change state case "Relationship": - parser.rln = &spdx.Relationship2_2{} + parser.rln = &v2_2.Relationship{} parser.doc.Relationships = append(parser.doc.Relationships, parser.rln) return parser.parsePairForRelationship2_2(tag, value) case "RelationshipComment": return parser.parsePairForRelationship2_2(tag, value) // for annotation tags, pass along but don't change state case "Annotator": - parser.ann = &spdx.Annotation2_2{} + parser.ann = &v2_2.Annotation{} parser.doc.Annotations = append(parser.doc.Annotations, parser.ann) return parser.parsePairForAnnotation2_2(tag, value) case "AnnotationDate": diff --git a/tvloader/parser2v2/parse_other_license_test.go b/tvloader/parser2v2/parse_other_license_test.go index e0607ee6..cdba8401 100644 --- a/tvloader/parser2v2/parse_other_license_test.go +++ b/tvloader/parser2v2/parse_other_license_test.go @@ -4,7 +4,7 @@ package parser2v2 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Parser other license section state change tests ===== @@ -14,11 +14,11 @@ func TestParser2_2OLStartsNewOtherLicenseAfterParsingLicenseIDTag(t *testing.T) olname1 := "License 11" parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psOtherLicense2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: olid1, LicenseName: olname1, }, @@ -90,10 +90,10 @@ func TestParser2_2OLStartsNewOtherLicenseAfterParsingLicenseIDTag(t *testing.T) func TestParser2_2OLMovesToReviewAfterParsingReviewerTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psOtherLicense2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -110,11 +110,11 @@ func TestParser2_2OLMovesToReviewAfterParsingReviewerTag(t *testing.T) { func TestParser2_2OtherLicenseStaysAfterParsingRelationshipTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psOtherLicense2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-whatever", LicenseName: "the whatever license", }, @@ -152,11 +152,11 @@ func TestParser2_2OtherLicenseStaysAfterParsingRelationshipTags(t *testing.T) { func TestParser2_2OtherLicenseStaysAfterParsingAnnotationTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psOtherLicense2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-whatever", LicenseName: "the whatever license", }, @@ -216,11 +216,11 @@ func TestParser2_2OtherLicenseStaysAfterParsingAnnotationTags(t *testing.T) { func TestParser2_2OLFailsAfterParsingOtherSectionTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psOtherLicense2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, @@ -247,10 +247,10 @@ func TestParser2_2OLFailsAfterParsingOtherSectionTags(t *testing.T) { // ===== Other License data section tests ===== func TestParser2_2CanParseOtherLicenseTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psOtherLicense2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -323,10 +323,10 @@ func TestParser2_2CanParseOtherLicenseTags(t *testing.T) { func TestParser2_2OLUnknownTagFails(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psOtherLicense2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) diff --git a/tvloader/parser2v2/parse_package.go b/tvloader/parser2v2/parse_package.go index 4d6caf9d..e8dbd7e7 100644 --- a/tvloader/parser2v2/parse_package.go +++ b/tvloader/parser2v2/parse_package.go @@ -6,7 +6,8 @@ import ( "fmt" "strings" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) func (parser *tvParser2_2) parsePairFromPackage2_2(tag string, value string) error { @@ -24,7 +25,7 @@ func (parser *tvParser2_2) parsePairFromPackage2_2(tag string, value string) err if parser.pkg != nil && parser.pkg.PackageSPDXIdentifier == nullSpdxElementId2_2 { return fmt.Errorf("package with PackageName %s does not have SPDX identifier", parser.pkg.PackageName) } - parser.pkg = &spdx.Package2_2{ + parser.pkg = &v2_2.Package{ FilesAnalyzed: true, IsFilesAnalyzedTagPresent: false, } @@ -45,7 +46,7 @@ func (parser *tvParser2_2) parsePairFromPackage2_2(tag string, value string) err } parser.pkg.PackageSPDXIdentifier = eID if parser.doc.Packages == nil { - parser.doc.Packages = []*spdx.Package2_2{} + parser.doc.Packages = []*v2_2.Package{} } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) case "PackageVersion": @@ -53,7 +54,7 @@ func (parser *tvParser2_2) parsePairFromPackage2_2(tag string, value string) err case "PackageFileName": parser.pkg.PackageFileName = value case "PackageSupplier": - supplier := &spdx.Supplier{Supplier: value} + supplier := &common.Supplier{Supplier: value} if value == "NOASSERTION" { parser.pkg.PackageSupplier = supplier break @@ -72,7 +73,7 @@ func (parser *tvParser2_2) parsePairFromPackage2_2(tag string, value string) err } parser.pkg.PackageSupplier = supplier case "PackageOriginator": - originator := &spdx.Originator{Originator: value} + originator := &common.Originator{Originator: value} if value == "NOASSERTION" { parser.pkg.PackageOriginator = originator break @@ -107,12 +108,12 @@ func (parser *tvParser2_2) parsePairFromPackage2_2(tag string, value string) err return err } if parser.pkg.PackageChecksums == nil { - parser.pkg.PackageChecksums = []spdx.Checksum{} + parser.pkg.PackageChecksums = []common.Checksum{} } - switch spdx.ChecksumAlgorithm(subkey) { - case spdx.SHA1, spdx.SHA256, spdx.MD5: - algorithm := spdx.ChecksumAlgorithm(subkey) - parser.pkg.PackageChecksums = append(parser.pkg.PackageChecksums, spdx.Checksum{Algorithm: algorithm, Value: subvalue}) + switch common.ChecksumAlgorithm(subkey) { + case common.SHA1, common.SHA256, common.MD5: + algorithm := common.ChecksumAlgorithm(subkey) + parser.pkg.PackageChecksums = append(parser.pkg.PackageChecksums, common.Checksum{Algorithm: algorithm, Value: subvalue}) default: return fmt.Errorf("got unknown checksum type %s", subkey) } @@ -139,7 +140,7 @@ func (parser *tvParser2_2) parsePairFromPackage2_2(tag string, value string) err case "PackageAttributionText": parser.pkg.PackageAttributionTexts = append(parser.pkg.PackageAttributionTexts, value) case "ExternalRef": - parser.pkgExtRef = &spdx.PackageExternalReference2_2{} + parser.pkgExtRef = &v2_2.PackageExternalReference{} parser.pkg.PackageExternalReferences = append(parser.pkg.PackageExternalReferences, parser.pkgExtRef) category, refType, locator, err := extractPackageExternalReference(value) if err != nil { @@ -157,14 +158,14 @@ func (parser *tvParser2_2) parsePairFromPackage2_2(tag string, value string) err parser.pkgExtRef = nil // for relationship tags, pass along but don't change state case "Relationship": - parser.rln = &spdx.Relationship2_2{} + parser.rln = &v2_2.Relationship{} parser.doc.Relationships = append(parser.doc.Relationships, parser.rln) return parser.parsePairForRelationship2_2(tag, value) case "RelationshipComment": return parser.parsePairForRelationship2_2(tag, value) // for annotation tags, pass along but don't change state case "Annotator": - parser.ann = &spdx.Annotation2_2{} + parser.ann = &v2_2.Annotation{} parser.doc.Annotations = append(parser.doc.Annotations, parser.ann) return parser.parsePairForAnnotation2_2(tag, value) case "AnnotationDate": @@ -188,13 +189,13 @@ func (parser *tvParser2_2) parsePairFromPackage2_2(tag string, value string) err // ===== Helper functions ===== -func extractCodeAndExcludes(value string) spdx.PackageVerificationCode { +func extractCodeAndExcludes(value string) common.PackageVerificationCode { // FIXME this should probably be done using regular expressions instead // split by paren + word "excludes:" sp := strings.SplitN(value, "(excludes:", 2) if len(sp) < 2 { // not found; return the whole string as just the code - return spdx.PackageVerificationCode{Value: value, ExcludedFiles: []string{}} + return common.PackageVerificationCode{Value: value, ExcludedFiles: []string{}} } // if we're here, code is in first part and excludes filename is in @@ -202,7 +203,7 @@ func extractCodeAndExcludes(value string) spdx.PackageVerificationCode { code := strings.TrimSpace(sp[0]) parsedSp := strings.SplitN(sp[1], ")", 2) fileName := strings.TrimSpace(parsedSp[0]) - return spdx.PackageVerificationCode{Value: code, ExcludedFiles: []string{fileName}} + return common.PackageVerificationCode{Value: code, ExcludedFiles: []string{fileName}} } func extractPackageExternalReference(value string) (string, string, string, error) { diff --git a/tvloader/parser2v2/parse_package_test.go b/tvloader/parser2v2/parse_package_test.go index 6b58d0f9..a1610f79 100644 --- a/tvloader/parser2v2/parse_package_test.go +++ b/tvloader/parser2v2/parse_package_test.go @@ -4,7 +4,8 @@ package parser2v2 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Parser package section state change tests ===== @@ -13,9 +14,9 @@ func TestParser2_2PackageStartsNewPackageAfterParsingPackageNameTag(t *testing.T pkgOldName := "p1" parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: pkgOldName, PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: pkgOldName, PackageSPDXIdentifier: "p1"}, } pkgOld := parser.pkg parser.doc.Packages = append(parser.doc.Packages, pkgOld) @@ -69,7 +70,7 @@ func TestParser2_2PackageStartsNewPackageAfterParsingPackageNameTagWhileInUnpack // pkg is nil, so that Files appearing before the first PackageName tag // are added to Files instead of Packages parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psFile2_2, pkg: nil, } @@ -112,9 +113,9 @@ func TestParser2_2PackageStartsNewPackageAfterParsingPackageNameTagWhileInUnpack func TestParser2_2PackageMovesToFileAfterParsingFileNameTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) pkgCurrent := parser.pkg @@ -135,9 +136,9 @@ func TestParser2_2PackageMovesToFileAfterParsingFileNameTag(t *testing.T) { func TestParser2_2PackageMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -152,9 +153,9 @@ func TestParser2_2PackageMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing. func TestParser2_2PackageMovesToReviewAfterParsingReviewerTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -169,9 +170,9 @@ func TestParser2_2PackageMovesToReviewAfterParsingReviewerTag(t *testing.T) { func TestParser2_2PackageStaysAfterParsingRelationshipTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -196,9 +197,9 @@ func TestParser2_2PackageStaysAfterParsingRelationshipTags(t *testing.T) { func TestParser2_2PackageStaysAfterParsingAnnotationTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -246,9 +247,9 @@ func TestParser2_2PackageStaysAfterParsingAnnotationTags(t *testing.T) { // ===== Package data section tests ===== func TestParser2_2CanParsePackageTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{}, + pkg: &v2_2.Package{}, } // should not yet be in Packages map, b/c no SPDX identifier @@ -355,15 +356,15 @@ func TestParser2_2CanParsePackageTags(t *testing.T) { } for _, checksum := range parser.pkg.PackageChecksums { switch checksum.Algorithm { - case spdx.SHA1: + case common.SHA1: if checksum.Value != codeSha1 { t.Errorf("expected %s for FileChecksumSHA1, got %s", codeSha1, checksum.Value) } - case spdx.SHA256: + case common.SHA256: if checksum.Value != codeSha256 { t.Errorf("expected %s for FileChecksumSHA1, got %s", codeSha256, checksum.Value) } - case spdx.MD5: + case common.MD5: if checksum.Value != codeMd5 { t.Errorf("expected %s for FileChecksumSHA1, got %s", codeMd5, checksum.Value) } @@ -589,9 +590,9 @@ func TestParser2_2CanParsePackageTags(t *testing.T) { func TestParser2_2CanParsePackageSupplierPersonTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -607,9 +608,9 @@ func TestParser2_2CanParsePackageSupplierPersonTag(t *testing.T) { func TestParser2_2CanParsePackageSupplierOrganizationTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -625,9 +626,9 @@ func TestParser2_2CanParsePackageSupplierOrganizationTag(t *testing.T) { func TestParser2_2CanParsePackageSupplierNOASSERTIONTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -643,9 +644,9 @@ func TestParser2_2CanParsePackageSupplierNOASSERTIONTag(t *testing.T) { func TestParser2_2CanParsePackageOriginatorPersonTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -661,9 +662,9 @@ func TestParser2_2CanParsePackageOriginatorPersonTag(t *testing.T) { func TestParser2_2CanParsePackageOriginatorOrganizationTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -679,9 +680,9 @@ func TestParser2_2CanParsePackageOriginatorOrganizationTag(t *testing.T) { func TestParser2_2CanParsePackageOriginatorNOASSERTIONTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -697,9 +698,9 @@ func TestParser2_2CanParsePackageOriginatorNOASSERTIONTag(t *testing.T) { func TestParser2_2CanParsePackageVerificationCodeTagWithExcludes(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -722,9 +723,9 @@ func TestParser2_2CanParsePackageVerificationCodeTagWithExcludes(t *testing.T) { func TestParser2_2CanParsePackageVerificationCodeTagWithoutExcludes(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -745,9 +746,9 @@ func TestParser2_2CanParsePackageVerificationCodeTagWithoutExcludes(t *testing.T func TestParser2_2PackageExternalRefPointerChangesAfterTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -790,9 +791,9 @@ func TestParser2_2PackageExternalRefPointerChangesAfterTags(t *testing.T) { func TestParser2_2PackageCreatesRelationshipInDocument(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -810,9 +811,9 @@ func TestParser2_2PackageCreatesRelationshipInDocument(t *testing.T) { func TestParser2_2PackageCreatesAnnotationInDocument(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -830,9 +831,9 @@ func TestParser2_2PackageCreatesAnnotationInDocument(t *testing.T) { func TestParser2_2PackageUnknownTagFails(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: "p1", PackageSPDXIdentifier: "p1"}, + pkg: &v2_2.Package{PackageName: "p1", PackageSPDXIdentifier: "p1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -844,9 +845,9 @@ func TestParser2_2PackageUnknownTagFails(t *testing.T) { func TestParser2_2FailsIfInvalidSPDXIDInPackageSection(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{}, + pkg: &v2_2.Package{}, } // start with Package Name @@ -863,9 +864,9 @@ func TestParser2_2FailsIfInvalidSPDXIDInPackageSection(t *testing.T) { func TestParser2_2FailsIfInvalidPackageSupplierFormat(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{}, + pkg: &v2_2.Package{}, } // start with Package Name @@ -882,9 +883,9 @@ func TestParser2_2FailsIfInvalidPackageSupplierFormat(t *testing.T) { func TestParser2_2FailsIfUnknownPackageSupplierType(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{}, + pkg: &v2_2.Package{}, } // start with Package Name @@ -901,9 +902,9 @@ func TestParser2_2FailsIfUnknownPackageSupplierType(t *testing.T) { func TestParser2_2FailsIfInvalidPackageOriginatorFormat(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{}, + pkg: &v2_2.Package{}, } // start with Package Name @@ -920,9 +921,9 @@ func TestParser2_2FailsIfInvalidPackageOriginatorFormat(t *testing.T) { func TestParser2_2FailsIfUnknownPackageOriginatorType(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{}, + pkg: &v2_2.Package{}, } // start with Package Name @@ -939,9 +940,9 @@ func TestParser2_2FailsIfUnknownPackageOriginatorType(t *testing.T) { func TestParser2_2SetsFilesAnalyzedTagsCorrectly(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{}, + pkg: &v2_2.Package{}, } // start with Package Name @@ -964,9 +965,9 @@ func TestParser2_2SetsFilesAnalyzedTagsCorrectly(t *testing.T) { func TestParser2_2FailsIfInvalidPackageChecksumFormat(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{}, + pkg: &v2_2.Package{}, } // start with Package Name @@ -983,9 +984,9 @@ func TestParser2_2FailsIfInvalidPackageChecksumFormat(t *testing.T) { func TestParser2_2FailsIfInvalidPackageChecksumType(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{}, + pkg: &v2_2.Package{}, } // start with Package Name @@ -1002,9 +1003,9 @@ func TestParser2_2FailsIfInvalidPackageChecksumType(t *testing.T) { func TestParser2_2FailsIfInvalidExternalRefFormat(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{}, + pkg: &v2_2.Package{}, } // start with Package Name @@ -1021,9 +1022,9 @@ func TestParser2_2FailsIfInvalidExternalRefFormat(t *testing.T) { func TestParser2_2FailsIfExternalRefCommentBeforeExternalRef(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{}, + pkg: &v2_2.Package{}, } // start with Package Name @@ -1107,9 +1108,9 @@ func TestParser2_2PackageWithoutSpdxIdentifierThrowsError(t *testing.T) { // More than one package, the previous package doesn't contain an SPDX ID pkgOldName := "p1" parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psPackage2_2, - pkg: &spdx.Package2_2{PackageName: pkgOldName}, + pkg: &v2_2.Package{PackageName: pkgOldName}, } pkgOld := parser.pkg parser.doc.Packages = append(parser.doc.Packages, pkgOld) diff --git a/tvloader/parser2v2/parse_relationship_test.go b/tvloader/parser2v2/parse_relationship_test.go index 0e6c013e..48285fc1 100644 --- a/tvloader/parser2v2/parse_relationship_test.go +++ b/tvloader/parser2v2/parse_relationship_test.go @@ -4,13 +4,13 @@ package parser2v2 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Relationship section tests ===== func TestParser2_2FailsIfRelationshipNotSet(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } err := parser.parsePairForRelationship2_2("Relationship", "SPDXRef-A CONTAINS SPDXRef-B") @@ -21,7 +21,7 @@ func TestParser2_2FailsIfRelationshipNotSet(t *testing.T) { func TestParser2_2FailsIfRelationshipCommentWithoutRelationship(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } err := parser.parsePair2_2("RelationshipComment", "comment whatever") @@ -32,7 +32,7 @@ func TestParser2_2FailsIfRelationshipCommentWithoutRelationship(t *testing.T) { func TestParser2_2CanParseRelationshipTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -64,7 +64,7 @@ func TestParser2_2CanParseRelationshipTags(t *testing.T) { func TestParser2_2InvalidRelationshipTagsNoValueFail(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -78,7 +78,7 @@ func TestParser2_2InvalidRelationshipTagsNoValueFail(t *testing.T) { func TestParser2_2InvalidRelationshipTagsOneValueFail(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -92,7 +92,7 @@ func TestParser2_2InvalidRelationshipTagsOneValueFail(t *testing.T) { func TestParser2_2InvalidRelationshipTagsTwoValuesFail(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -106,7 +106,7 @@ func TestParser2_2InvalidRelationshipTagsTwoValuesFail(t *testing.T) { func TestParser2_2InvalidRelationshipTagsThreeValuesSucceed(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -120,7 +120,7 @@ func TestParser2_2InvalidRelationshipTagsThreeValuesSucceed(t *testing.T) { func TestParser2_2InvalidRelationshipTagsFourValuesFail(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -134,7 +134,7 @@ func TestParser2_2InvalidRelationshipTagsFourValuesFail(t *testing.T) { func TestParser2_2InvalidRelationshipTagsInvalidRefIDs(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -154,7 +154,7 @@ func TestParser2_2InvalidRelationshipTagsInvalidRefIDs(t *testing.T) { func TestParser2_2SpecialValuesValidForRightSideOfRelationship(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } @@ -185,7 +185,7 @@ func TestParser2_2SpecialValuesValidForRightSideOfRelationship(t *testing.T) { func TestParser2_2FailsToParseUnknownTagInRelationshipSection(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, } diff --git a/tvloader/parser2v2/parse_review.go b/tvloader/parser2v2/parse_review.go index 065d889d..09691c87 100644 --- a/tvloader/parser2v2/parse_review.go +++ b/tvloader/parser2v2/parse_review.go @@ -5,14 +5,14 @@ package parser2v2 import ( "fmt" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) func (parser *tvParser2_2) parsePairFromReview2_2(tag string, value string) error { switch tag { // tag for creating new review section case "Reviewer": - parser.rev = &spdx.Review2_2{} + parser.rev = &v2_2.Review{} parser.doc.Reviews = append(parser.doc.Reviews, parser.rev) subkey, subvalue, err := extractSubs(value) if err != nil { @@ -37,14 +37,14 @@ func (parser *tvParser2_2) parsePairFromReview2_2(tag string, value string) erro parser.rev.ReviewComment = value // for relationship tags, pass along but don't change state case "Relationship": - parser.rln = &spdx.Relationship2_2{} + parser.rln = &v2_2.Relationship{} parser.doc.Relationships = append(parser.doc.Relationships, parser.rln) return parser.parsePairForRelationship2_2(tag, value) case "RelationshipComment": return parser.parsePairForRelationship2_2(tag, value) // for annotation tags, pass along but don't change state case "Annotator": - parser.ann = &spdx.Annotation2_2{} + parser.ann = &v2_2.Annotation{} parser.doc.Annotations = append(parser.doc.Annotations, parser.ann) return parser.parsePairForAnnotation2_2(tag, value) case "AnnotationDate": diff --git a/tvloader/parser2v2/parse_review_test.go b/tvloader/parser2v2/parse_review_test.go index de73ede0..f93afbf8 100644 --- a/tvloader/parser2v2/parse_review_test.go +++ b/tvloader/parser2v2/parse_review_test.go @@ -4,7 +4,7 @@ package parser2v2 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Parser review section state change tests ===== @@ -12,15 +12,15 @@ func TestParser2_2ReviewStartsNewReviewAfterParsingReviewerTag(t *testing.T) { // create the first review rev1 := "John Doe" parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psReview2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_2{ + rev: &v2_2.Review{ Reviewer: rev1, ReviewerType: "Person", }, @@ -82,15 +82,15 @@ func TestParser2_2ReviewStartsNewReviewAfterParsingReviewerTag(t *testing.T) { func TestParser2_2ReviewStaysAfterParsingRelationshipTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psReview2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_2{ + rev: &v2_2.Review{ Reviewer: "Jane Doe", ReviewerType: "Person", }, @@ -129,15 +129,15 @@ func TestParser2_2ReviewStaysAfterParsingRelationshipTags(t *testing.T) { func TestParser2_2ReviewStaysAfterParsingAnnotationTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psReview2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_2{ + rev: &v2_2.Review{ Reviewer: "Jane Doe", ReviewerType: "Person", }, @@ -198,15 +198,15 @@ func TestParser2_2ReviewStaysAfterParsingAnnotationTags(t *testing.T) { func TestParser2_2ReviewFailsAfterParsingOtherSectionTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psReview2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_2{}, + rev: &v2_2.Review{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -235,15 +235,15 @@ func TestParser2_2ReviewFailsAfterParsingOtherSectionTags(t *testing.T) { // ===== Review data section tests ===== func TestParser2_2CanParseReviewTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psReview2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_2{}, + rev: &v2_2.Review{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -274,15 +274,15 @@ func TestParser2_2CanParseReviewTags(t *testing.T) { func TestParser2_2CanParseReviewerPersonTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psReview2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_2{}, + rev: &v2_2.Review{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -304,15 +304,15 @@ func TestParser2_2CanParseReviewerPersonTag(t *testing.T) { func TestParser2_2CanParseReviewerOrganizationTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psReview2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_2{}, + rev: &v2_2.Review{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -334,15 +334,15 @@ func TestParser2_2CanParseReviewerOrganizationTag(t *testing.T) { func TestParser2_2CanParseReviewerToolTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psReview2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_2{}, + rev: &v2_2.Review{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -364,9 +364,9 @@ func TestParser2_2CanParseReviewerToolTag(t *testing.T) { func TestParser2_2FailsIfReviewerInvalidFormat(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psReview2_2, - rev: &spdx.Review2_2{}, + rev: &v2_2.Review{}, } parser.doc.Reviews = append(parser.doc.Reviews, parser.rev) @@ -378,9 +378,9 @@ func TestParser2_2FailsIfReviewerInvalidFormat(t *testing.T) { func TestParser2_2FailsIfReviewerUnknownType(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psReview2_2, - rev: &spdx.Review2_2{}, + rev: &v2_2.Review{}, } parser.doc.Reviews = append(parser.doc.Reviews, parser.rev) @@ -392,15 +392,15 @@ func TestParser2_2FailsIfReviewerUnknownType(t *testing.T) { func TestParser2_2ReviewUnknownTagFails(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psReview2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, - otherLic: &spdx.OtherLicense2_2{ + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1"}, + otherLic: &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-Lic11", LicenseName: "License 11", }, - rev: &spdx.Review2_2{}, + rev: &v2_2.Review{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) diff --git a/tvloader/parser2v2/parse_snippet.go b/tvloader/parser2v2/parse_snippet.go index d3bac476..5b4f41a0 100644 --- a/tvloader/parser2v2/parse_snippet.go +++ b/tvloader/parser2v2/parse_snippet.go @@ -6,7 +6,8 @@ import ( "fmt" "strconv" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) func (parser *tvParser2_2) parsePairFromSnippet2_2(tag string, value string) error { @@ -17,7 +18,7 @@ func (parser *tvParser2_2) parsePairFromSnippet2_2(tag string, value string) err if parser.file != nil && parser.file.FileSPDXIdentifier == nullSpdxElementId2_2 { return fmt.Errorf("file with FileName %s does not have SPDX identifier", parser.file.FileName) } - parser.snippet = &spdx.Snippet2_2{} + parser.snippet = &v2_2.Snippet{} eID, err := extractElementID(value) if err != nil { return err @@ -25,7 +26,7 @@ func (parser *tvParser2_2) parsePairFromSnippet2_2(tag string, value string) err // FIXME: how should we handle where not associated with current file? if parser.file != nil { if parser.file.Snippets == nil { - parser.file.Snippets = map[spdx.ElementID]*spdx.Snippet2_2{} + parser.file.Snippets = map[common.ElementID]*v2_2.Snippet{} } parser.file.Snippets[eID] = parser.snippet } @@ -67,9 +68,9 @@ func (parser *tvParser2_2) parsePairFromSnippet2_2(tag string, value string) err } if parser.snippet.Ranges == nil { - parser.snippet.Ranges = []spdx.SnippetRange{} + parser.snippet.Ranges = []common.SnippetRange{} } - byteRange := spdx.SnippetRange{StartPointer: spdx.SnippetRangePointer{Offset: bIntStart}, EndPointer: spdx.SnippetRangePointer{Offset: bIntEnd}} + byteRange := common.SnippetRange{StartPointer: common.SnippetRangePointer{Offset: bIntStart}, EndPointer: common.SnippetRangePointer{Offset: bIntEnd}} parser.snippet.Ranges = append(parser.snippet.Ranges, byteRange) case "SnippetLineRange": lineStart, lineEnd, err := extractSubs(value) @@ -86,9 +87,9 @@ func (parser *tvParser2_2) parsePairFromSnippet2_2(tag string, value string) err } if parser.snippet.Ranges == nil { - parser.snippet.Ranges = []spdx.SnippetRange{} + parser.snippet.Ranges = []common.SnippetRange{} } - lineRange := spdx.SnippetRange{StartPointer: spdx.SnippetRangePointer{LineNumber: lInttStart}, EndPointer: spdx.SnippetRangePointer{LineNumber: lInttEnd}} + lineRange := common.SnippetRange{StartPointer: common.SnippetRangePointer{LineNumber: lInttStart}, EndPointer: common.SnippetRangePointer{LineNumber: lInttEnd}} parser.snippet.Ranges = append(parser.snippet.Ranges, lineRange) case "SnippetLicenseConcluded": parser.snippet.SnippetLicenseConcluded = value @@ -106,14 +107,14 @@ func (parser *tvParser2_2) parsePairFromSnippet2_2(tag string, value string) err parser.snippet.SnippetAttributionTexts = append(parser.snippet.SnippetAttributionTexts, value) // for relationship tags, pass along but don't change state case "Relationship": - parser.rln = &spdx.Relationship2_2{} + parser.rln = &v2_2.Relationship{} parser.doc.Relationships = append(parser.doc.Relationships, parser.rln) return parser.parsePairForRelationship2_2(tag, value) case "RelationshipComment": return parser.parsePairForRelationship2_2(tag, value) // for annotation tags, pass along but don't change state case "Annotator": - parser.ann = &spdx.Annotation2_2{} + parser.ann = &v2_2.Annotation{} parser.doc.Annotations = append(parser.doc.Annotations, parser.ann) return parser.parsePairForAnnotation2_2(tag, value) case "AnnotationDate": diff --git a/tvloader/parser2v2/parse_snippet_test.go b/tvloader/parser2v2/parse_snippet_test.go index 545595af..1d6ddb2b 100644 --- a/tvloader/parser2v2/parse_snippet_test.go +++ b/tvloader/parser2v2/parse_snippet_test.go @@ -4,19 +4,20 @@ package parser2v2 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Parser snippet section state change tests ===== func TestParser2_2SnippetStartsNewSnippetAfterParsingSnippetSPDXIDTag(t *testing.T) { // create the first snippet - sid1 := spdx.ElementID("s1") + sid1 := common.ElementID("s1") parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{SnippetSPDXIdentifier: sid1}, + pkg: &v2_2.Package{PackageName: "test", PackageSPDXIdentifier: "test", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{SnippetSPDXIdentifier: sid1}, } s1 := parser.snippet parser.doc.Packages = append(parser.doc.Packages, parser.pkg) @@ -71,11 +72,11 @@ func TestParser2_2SnippetStartsNewSnippetAfterParsingSnippetSPDXIDTag(t *testing func TestParser2_2SnippetStartsNewPackageAfterParsingPackageNameTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_2.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{SnippetSPDXIdentifier: "s1"}, } p1 := parser.pkg f1 := parser.file @@ -146,11 +147,11 @@ func TestParser2_2SnippetStartsNewPackageAfterParsingPackageNameTag(t *testing.T func TestParser2_2SnippetMovesToFileAfterParsingFileNameTag(t *testing.T) { f1Name := "f1.txt" parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_2.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{SnippetSPDXIdentifier: "s1"}, } p1 := parser.pkg f1 := parser.file @@ -198,11 +199,11 @@ func TestParser2_2SnippetMovesToFileAfterParsingFileNameTag(t *testing.T) { func TestParser2_2SnippetMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_2.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{SnippetSPDXIdentifier: "s1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -219,11 +220,11 @@ func TestParser2_2SnippetMovesToOtherLicenseAfterParsingLicenseIDTag(t *testing. func TestParser2_2SnippetMovesToReviewAfterParsingReviewerTag(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_2.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{SnippetSPDXIdentifier: "s1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -240,11 +241,11 @@ func TestParser2_2SnippetMovesToReviewAfterParsingReviewerTag(t *testing.T) { func TestParser2_2SnippetStaysAfterParsingRelationshipTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_2.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{SnippetSPDXIdentifier: "s1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -279,11 +280,11 @@ func TestParser2_2SnippetStaysAfterParsingRelationshipTags(t *testing.T) { func TestParser2_2SnippetStaysAfterParsingAnnotationTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_2.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{SnippetSPDXIdentifier: "s1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -341,11 +342,11 @@ func TestParser2_2SnippetStaysAfterParsingAnnotationTags(t *testing.T) { // ===== Snippet data section tests ===== func TestParser2_2CanParseSnippetTags(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{}, + pkg: &v2_2.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -364,7 +365,7 @@ func TestParser2_2CanParseSnippetTags(t *testing.T) { if err != nil { t.Errorf("expected nil error, got %v", err) } - wantDeID := spdx.DocElementID{DocumentRefID: "", ElementRefID: spdx.ElementID("f1")} + wantDeID := common.DocElementID{DocumentRefID: "", ElementRefID: common.ElementID("f1")} if parser.snippet.SnippetFromFileSPDXIdentifier != wantDeID.ElementRefID { t.Errorf("got %v for SnippetFromFileSPDXIdentifier", parser.snippet.SnippetFromFileSPDXIdentifier) } @@ -497,11 +498,11 @@ func TestParser2_2CanParseSnippetTags(t *testing.T) { func TestParser2_2SnippetUnknownTagFails(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{SnippetSPDXIdentifier: "s1"}, + pkg: &v2_2.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{SnippetSPDXIdentifier: "s1"}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -514,11 +515,11 @@ func TestParser2_2SnippetUnknownTagFails(t *testing.T) { func TestParser2_2FailsForInvalidSnippetSPDXID(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{}, + pkg: &v2_2.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -532,11 +533,11 @@ func TestParser2_2FailsForInvalidSnippetSPDXID(t *testing.T) { func TestParser2_2FailsForInvalidSnippetFromFileSPDXID(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{}, + pkg: &v2_2.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -555,11 +556,11 @@ func TestParser2_2FailsForInvalidSnippetFromFileSPDXID(t *testing.T) { func TestParser2_2FailsForInvalidSnippetByteValues(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{}, + pkg: &v2_2.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -586,11 +587,11 @@ func TestParser2_2FailsForInvalidSnippetByteValues(t *testing.T) { func TestParser2_2FailsForInvalidSnippetLineValues(t *testing.T) { parser := tvParser2_2{ - doc: &spdx.Document2_2{Packages: []*spdx.Package2_2{}}, + doc: &v2_2.Document{Packages: []*v2_2.Package{}}, st: psSnippet2_2, - pkg: &spdx.Package2_2{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*spdx.File2_2{}}, - file: &spdx.File2_2{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[spdx.ElementID]*spdx.Snippet2_2{}}, - snippet: &spdx.Snippet2_2{}, + pkg: &v2_2.Package{PackageName: "package1", PackageSPDXIdentifier: "package1", Files: []*v2_2.File{}}, + file: &v2_2.File{FileName: "f1.txt", FileSPDXIdentifier: "f1", Snippets: map[common.ElementID]*v2_2.Snippet{}}, + snippet: &v2_2.Snippet{}, } parser.doc.Packages = append(parser.doc.Packages, parser.pkg) parser.pkg.Files = append(parser.pkg.Files, parser.file) @@ -620,11 +621,11 @@ func TestParser2_2FilesWithoutSpdxIdThrowErrorWithSnippets(t *testing.T) { // Last unpackaged file before the snippet starts // Last file of a package and New package starts fileName := "f2.txt" - sid1 := spdx.ElementID("s1") + sid1 := common.ElementID("s1") parser2 := tvParser2_2{ - doc: &spdx.Document2_2{}, + doc: &v2_2.Document{}, st: psCreationInfo2_2, - file: &spdx.File2_2{FileName: fileName}, + file: &v2_2.File{FileName: fileName}, } err := parser2.parsePair2_2("SnippetSPDXID", string(sid1)) if err == nil { diff --git a/tvloader/parser2v2/parser.go b/tvloader/parser2v2/parser.go index 1d9f8e9c..72f67beb 100644 --- a/tvloader/parser2v2/parser.go +++ b/tvloader/parser2v2/parser.go @@ -6,13 +6,14 @@ package parser2v2 import ( "fmt" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" "github.com/spdx/tools-golang/tvloader/reader" ) // ParseTagValues takes a list of (tag, value) pairs, parses it and returns // a pointer to a parsed SPDX Document. -func ParseTagValues(tvs []reader.TagValuePair) (*spdx.Document2_2, error) { +func ParseTagValues(tvs []reader.TagValuePair) (*v2_2.Document, error) { parser := tvParser2_2{} for _, tv := range tvs { err := parser.parsePair2_2(tv.Tag, tv.Value) @@ -58,7 +59,7 @@ func (parser *tvParser2_2) parsePairFromStart2_2(tag string, value string) error // create an SPDX Document data struct if we don't have one already if parser.doc == nil { - parser.doc = &spdx.Document2_2{ExternalDocumentReferences: []spdx.ExternalDocumentRef2_2{}} + parser.doc = &v2_2.Document{ExternalDocumentReferences: []v2_2.ExternalDocumentRef{}} } switch tag { @@ -83,10 +84,10 @@ func (parser *tvParser2_2) parsePairFromStart2_2(tag string, value string) error if err != nil { return err } - edr := spdx.ExternalDocumentRef2_2{ + edr := v2_2.ExternalDocumentRef{ DocumentRefID: documentRefID, URI: uri, - Checksum: spdx.Checksum{Algorithm: spdx.ChecksumAlgorithm(alg), Value: checksum}, + Checksum: common.Checksum{Algorithm: common.ChecksumAlgorithm(alg), Value: checksum}, } parser.doc.ExternalDocumentReferences = append(parser.doc.ExternalDocumentReferences, edr) default: diff --git a/tvloader/parser2v2/types.go b/tvloader/parser2v2/types.go index 1cdbcef5..52d6a9ac 100644 --- a/tvloader/parser2v2/types.go +++ b/tvloader/parser2v2/types.go @@ -3,26 +3,27 @@ package parser2v2 import ( - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) type tvParser2_2 struct { // document into which data is being parsed - doc *spdx.Document2_2 + doc *v2_2.Document // current parser state st tvParserState2_2 // current SPDX item being filled in, if any - pkg *spdx.Package2_2 - pkgExtRef *spdx.PackageExternalReference2_2 - file *spdx.File2_2 - fileAOP *spdx.ArtifactOfProject2_2 - snippet *spdx.Snippet2_2 - otherLic *spdx.OtherLicense2_2 - rln *spdx.Relationship2_2 - ann *spdx.Annotation2_2 - rev *spdx.Review2_2 + pkg *v2_2.Package + pkgExtRef *v2_2.PackageExternalReference + file *v2_2.File + fileAOP *v2_2.ArtifactOfProject + snippet *v2_2.Snippet + otherLic *v2_2.OtherLicense + rln *v2_2.Relationship + ann *v2_2.Annotation + rev *v2_2.Review // don't need creation info pointer b/c only one, // and we can get to it via doc.CreationInfo } @@ -53,4 +54,4 @@ const ( psReview2_2 ) -const nullSpdxElementId2_2 = spdx.ElementID("") +const nullSpdxElementId2_2 = common.ElementID("") diff --git a/tvloader/parser2v2/util.go b/tvloader/parser2v2/util.go index 66768469..5e844338 100644 --- a/tvloader/parser2v2/util.go +++ b/tvloader/parser2v2/util.go @@ -6,7 +6,7 @@ import ( "fmt" "strings" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" ) // used to extract key / value from embedded substrings @@ -26,7 +26,7 @@ func extractSubs(value string) (string, string, error) { // used to extract DocumentRef and SPDXRef values from an SPDX Identifier // which can point either to this document or to a different one -func extractDocElementID(value string) (spdx.DocElementID, error) { +func extractDocElementID(value string) (common.DocElementID, error) { docRefID := "" idStr := value @@ -36,16 +36,16 @@ func extractDocElementID(value string) (spdx.DocElementID, error) { strs := strings.Split(idStr, ":") // should be exactly two, part before and part after if len(strs) < 2 { - return spdx.DocElementID{}, fmt.Errorf("no colon found although DocumentRef- prefix present") + return common.DocElementID{}, fmt.Errorf("no colon found although DocumentRef- prefix present") } if len(strs) > 2 { - return spdx.DocElementID{}, fmt.Errorf("more than one colon found") + return common.DocElementID{}, fmt.Errorf("more than one colon found") } // trim the prefix and confirm non-empty docRefID = strings.TrimPrefix(strs[0], "DocumentRef-") if docRefID == "" { - return spdx.DocElementID{}, fmt.Errorf("document identifier has nothing after prefix") + return common.DocElementID{}, fmt.Errorf("document identifier has nothing after prefix") } // and use remainder for element ID parsing idStr = strs[1] @@ -53,24 +53,24 @@ func extractDocElementID(value string) (spdx.DocElementID, error) { // check prefix to confirm it's got the right prefix for element IDs if !strings.HasPrefix(idStr, "SPDXRef-") { - return spdx.DocElementID{}, fmt.Errorf("missing SPDXRef- prefix for element identifier") + return common.DocElementID{}, fmt.Errorf("missing SPDXRef- prefix for element identifier") } // make sure no colons are present if strings.Contains(idStr, ":") { // we know this means there was no DocumentRef- prefix, because // we would have handled multiple colons above if it was - return spdx.DocElementID{}, fmt.Errorf("invalid colon in element identifier") + return common.DocElementID{}, fmt.Errorf("invalid colon in element identifier") } // trim the prefix and confirm non-empty eltRefID := strings.TrimPrefix(idStr, "SPDXRef-") if eltRefID == "" { - return spdx.DocElementID{}, fmt.Errorf("element identifier has nothing after prefix") + return common.DocElementID{}, fmt.Errorf("element identifier has nothing after prefix") } // we're good - return spdx.DocElementID{DocumentRefID: docRefID, ElementRefID: spdx.ElementID(eltRefID)}, nil + return common.DocElementID{DocumentRefID: docRefID, ElementRefID: common.ElementID(eltRefID)}, nil } // used to extract SPDXRef values from an SPDX Identifier, OR "special" strings @@ -79,11 +79,11 @@ func extractDocElementID(value string) (spdx.DocElementID, error) { // "NONE" and "NOASSERTION" are permitted. If the value does not match one of // the specified permitted values, it will fall back to the ordinary // DocElementID extractor. -func extractDocElementSpecial(value string, permittedSpecial []string) (spdx.DocElementID, error) { +func extractDocElementSpecial(value string, permittedSpecial []string) (common.DocElementID, error) { // check value against special set first for _, sp := range permittedSpecial { if sp == value { - return spdx.DocElementID{SpecialID: sp}, nil + return common.DocElementID{SpecialID: sp}, nil } } // not found, fall back to regular search @@ -93,23 +93,23 @@ func extractDocElementSpecial(value string, permittedSpecial []string) (spdx.Doc // used to extract SPDXRef values only from an SPDX Identifier which can point // to this document only. Use extractDocElementID for parsing IDs that can // refer either to this document or a different one. -func extractElementID(value string) (spdx.ElementID, error) { +func extractElementID(value string) (common.ElementID, error) { // check prefix to confirm it's got the right prefix for element IDs if !strings.HasPrefix(value, "SPDXRef-") { - return spdx.ElementID(""), fmt.Errorf("missing SPDXRef- prefix for element identifier") + return common.ElementID(""), fmt.Errorf("missing SPDXRef- prefix for element identifier") } // make sure no colons are present if strings.Contains(value, ":") { - return spdx.ElementID(""), fmt.Errorf("invalid colon in element identifier") + return common.ElementID(""), fmt.Errorf("invalid colon in element identifier") } // trim the prefix and confirm non-empty eltRefID := strings.TrimPrefix(value, "SPDXRef-") if eltRefID == "" { - return spdx.ElementID(""), fmt.Errorf("element identifier has nothing after prefix") + return common.ElementID(""), fmt.Errorf("element identifier has nothing after prefix") } // we're good - return spdx.ElementID(eltRefID), nil + return common.ElementID(eltRefID), nil } diff --git a/tvloader/parser2v2/util_test.go b/tvloader/parser2v2/util_test.go index e2f75d7b..80050f36 100644 --- a/tvloader/parser2v2/util_test.go +++ b/tvloader/parser2v2/util_test.go @@ -4,7 +4,7 @@ package parser2v2 import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" ) // ===== Helper function tests ===== @@ -65,7 +65,7 @@ func helperForExtractDocElementID(t *testing.T, tst string, wantErr bool, wantDo t.Errorf("testing %v: want %v for DocumentRefID, got %v", tst, wantDoc, deID.DocumentRefID) } } - if deID.ElementRefID != spdx.ElementID(wantElt) { + if deID.ElementRefID != common.ElementID(wantElt) { if wantElt == "" { t.Errorf("testing %v: want empty string for ElementRefID, got %v", tst, deID.ElementRefID) } else { @@ -103,7 +103,7 @@ func helperForExtractDocElementSpecial(t *testing.T, permittedSpecial []string, t.Errorf("testing %v: want %v for DocumentRefID, got %v", tst, wantDoc, deID.DocumentRefID) } } - if deID.ElementRefID != spdx.ElementID(wantElt) { + if deID.ElementRefID != common.ElementID(wantElt) { if wantElt == "" { t.Errorf("testing %v: want empty string for ElementRefID, got %v", tst, deID.ElementRefID) } else { @@ -146,7 +146,7 @@ func helperForExtractElementID(t *testing.T, tst string, wantErr bool, wantElt s if err == nil && wantErr == true { t.Errorf("testing %v: expected non-nil error, got nil", tst) } - if eID != spdx.ElementID(wantElt) { + if eID != common.ElementID(wantElt) { if wantElt == "" { t.Errorf("testing %v: want emptyString for ElementRefID, got %v", tst, eID) } else { diff --git a/tvloader/tvloader.go b/tvloader/tvloader.go index 4ad95b1c..b435f2cf 100644 --- a/tvloader/tvloader.go +++ b/tvloader/tvloader.go @@ -6,7 +6,8 @@ package tvloader import ( "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" "github.com/spdx/tools-golang/tvloader/parser2v1" "github.com/spdx/tools-golang/tvloader/parser2v2" "github.com/spdx/tools-golang/tvloader/reader" @@ -14,7 +15,7 @@ import ( // Load2_1 takes an io.Reader and returns a fully-parsed SPDX Document // (version 2.1) if parseable, or error if any error is encountered. -func Load2_1(content io.Reader) (*spdx.Document2_1, error) { +func Load2_1(content io.Reader) (*v2_1.Document, error) { tvPairs, err := reader.ReadTagValues(content) if err != nil { return nil, err @@ -30,7 +31,7 @@ func Load2_1(content io.Reader) (*spdx.Document2_1, error) { // Load2_2 takes an io.Reader and returns a fully-parsed SPDX Document // (version 2.2) if parseable, or error if any error is encountered. -func Load2_2(content io.Reader) (*spdx.Document2_2, error) { +func Load2_2(content io.Reader) (*v2_2.Document, error) { tvPairs, err := reader.ReadTagValues(content) if err != nil { return nil, err diff --git a/tvsaver/saver2v1/save_annotation.go b/tvsaver/saver2v1/save_annotation.go index f7d79538..3fa351fd 100644 --- a/tvsaver/saver2v1/save_annotation.go +++ b/tvsaver/saver2v1/save_annotation.go @@ -6,10 +6,11 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderAnnotation2_1(ann *spdx.Annotation2_1, w io.Writer) error { +func renderAnnotation2_1(ann *v2_1.Annotation, w io.Writer) error { if ann.Annotator.Annotator != "" && ann.Annotator.AnnotatorType != "" { fmt.Fprintf(w, "Annotator: %s: %s\n", ann.Annotator.AnnotatorType, ann.Annotator.Annotator) } @@ -19,7 +20,7 @@ func renderAnnotation2_1(ann *spdx.Annotation2_1, w io.Writer) error { if ann.AnnotationType != "" { fmt.Fprintf(w, "AnnotationType: %s\n", ann.AnnotationType) } - annIDStr := spdx.RenderDocElementID(ann.AnnotationSPDXIdentifier) + annIDStr := common.RenderDocElementID(ann.AnnotationSPDXIdentifier) if annIDStr != "SPDXRef-" { fmt.Fprintf(w, "SPDXREF: %s\n", annIDStr) } diff --git a/tvsaver/saver2v1/save_annotation_test.go b/tvsaver/saver2v1/save_annotation_test.go index 3eef5a72..405bf8aa 100644 --- a/tvsaver/saver2v1/save_annotation_test.go +++ b/tvsaver/saver2v1/save_annotation_test.go @@ -6,16 +6,17 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Annotation section Saver tests ===== func TestSaver2_1AnnotationSavesTextForPerson(t *testing.T) { - ann := &spdx.Annotation2_1{ - Annotator: spdx.Annotator{AnnotatorType: "Person", Annotator: "John Doe"}, + ann := &v2_1.Annotation{ + Annotator: common.Annotator{AnnotatorType: "Person", Annotator: "John Doe"}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "DOCUMENT"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "DOCUMENT"), AnnotationComment: "This is an annotation about the SPDX document", } @@ -43,11 +44,11 @@ AnnotationComment: This is an annotation about the SPDX document } func TestSaver2_1AnnotationSavesTextForOrganization(t *testing.T) { - ann := &spdx.Annotation2_1{ - Annotator: spdx.Annotator{AnnotatorType: "Organization", Annotator: "John Doe, Inc."}, + ann := &v2_1.Annotation{ + Annotator: common.Annotator{AnnotatorType: "Organization", Annotator: "John Doe, Inc."}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "DOCUMENT"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "DOCUMENT"), AnnotationComment: "This is an annotation about the SPDX document", } @@ -75,11 +76,11 @@ AnnotationComment: This is an annotation about the SPDX document } func TestSaver2_1AnnotationSavesTextForTool(t *testing.T) { - ann := &spdx.Annotation2_1{ - Annotator: spdx.Annotator{AnnotatorType: "Tool", Annotator: "magictool-1.1"}, + ann := &v2_1.Annotation{ + Annotator: common.Annotator{AnnotatorType: "Tool", Annotator: "magictool-1.1"}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "DOCUMENT"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "DOCUMENT"), AnnotationComment: "This is an annotation about the SPDX document", } diff --git a/tvsaver/saver2v1/save_creation_info.go b/tvsaver/saver2v1/save_creation_info.go index de8b107a..e4b5992c 100644 --- a/tvsaver/saver2v1/save_creation_info.go +++ b/tvsaver/saver2v1/save_creation_info.go @@ -4,11 +4,12 @@ package saver2v1 import ( "fmt" - "github.com/spdx/tools-golang/spdx" "io" + + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderCreationInfo2_1(ci *spdx.CreationInfo2_1, w io.Writer) error { +func renderCreationInfo2_1(ci *v2_1.CreationInfo, w io.Writer) error { if ci.LicenseListVersion != "" { fmt.Fprintf(w, "LicenseListVersion: %s\n", ci.LicenseListVersion) } diff --git a/tvsaver/saver2v1/save_creation_info_test.go b/tvsaver/saver2v1/save_creation_info_test.go index 1784cf59..52257359 100644 --- a/tvsaver/saver2v1/save_creation_info_test.go +++ b/tvsaver/saver2v1/save_creation_info_test.go @@ -6,14 +6,15 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Creation Info section Saver tests ===== func TestSaver2_1CISavesText(t *testing.T) { - ci := &spdx.CreationInfo2_1{ + ci := &v2_1.CreationInfo{ LicenseListVersion: "2.0", - Creators: []spdx.Creator{ + Creators: []common.Creator{ {Creator: "John Doe", CreatorType: "Person"}, {Creator: "Jane Doe (janedoe@example.com)", CreatorType: "Person"}, {Creator: "John Doe, Inc.", CreatorType: "Organization"}, @@ -56,8 +57,8 @@ CreatorComment: this is a creator comment func TestSaver2_1CIOmitsOptionalFieldsIfEmpty(t *testing.T) { // --- need at least one creator; do first for Persons --- - ci1 := &spdx.CreationInfo2_1{ - Creators: []spdx.Creator{ + ci1 := &v2_1.CreationInfo{ + Creators: []common.Creator{ {Creator: "John Doe", CreatorType: "Person"}, }, Created: "2018-10-10T06:20:00Z", @@ -83,8 +84,8 @@ Created: 2018-10-10T06:20:00Z } // --- need at least one creator; now switch to organization --- - ci2 := &spdx.CreationInfo2_1{ - Creators: []spdx.Creator{ + ci2 := &v2_1.CreationInfo{ + Creators: []common.Creator{ {Creator: "John Doe, Inc.", CreatorType: "Organization"}, }, Created: "2018-10-10T06:20:00Z", diff --git a/tvsaver/saver2v1/save_document.go b/tvsaver/saver2v1/save_document.go index ea17db25..1db4bf6d 100644 --- a/tvsaver/saver2v1/save_document.go +++ b/tvsaver/saver2v1/save_document.go @@ -9,14 +9,15 @@ import ( "io" "sort" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // RenderDocument2_1 is the main entry point to take an SPDX in-memory // Document (version 2.1), and render it to the received io.Writer. // It is only exported in order to be available to the tvsaver package, // and typically does not need to be called by client code. -func RenderDocument2_1(doc *spdx.Document2_1, w io.Writer) error { +func RenderDocument2_1(doc *v2_1.Document, w io.Writer) error { if doc.CreationInfo == nil { return fmt.Errorf("Document had nil CreationInfo section") } @@ -28,7 +29,7 @@ func RenderDocument2_1(doc *spdx.Document2_1, w io.Writer) error { fmt.Fprintf(w, "DataLicense: %s\n", doc.DataLicense) } if doc.SPDXIdentifier != "" { - fmt.Fprintf(w, "SPDXID: %s\n", spdx.RenderElementID(doc.SPDXIdentifier)) + fmt.Fprintf(w, "SPDXID: %s\n", common.RenderElementID(doc.SPDXIdentifier)) } if doc.DocumentName != "" { fmt.Fprintf(w, "DocumentName: %s\n", doc.DocumentName) diff --git a/tvsaver/saver2v1/save_document_test.go b/tvsaver/saver2v1/save_document_test.go index b1865647..1447c07a 100644 --- a/tvsaver/saver2v1/save_document_test.go +++ b/tvsaver/saver2v1/save_document_test.go @@ -6,65 +6,66 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== entire Document Saver tests ===== func TestSaver2_1DocumentSavesText(t *testing.T) { // Creation Info section - ci := &spdx.CreationInfo2_1{ - Creators: []spdx.Creator{ + ci := &v2_1.CreationInfo{ + Creators: []common.Creator{ {Creator: "John Doe", CreatorType: "Person"}, }, Created: "2018-10-10T06:20:00Z", } // unpackaged files - f1 := &spdx.File2_1{ + f1 := &v2_1.File{ FileName: "/tmp/whatever1.txt", - FileSPDXIdentifier: spdx.ElementID("File1231"), - Checksums: []spdx.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983c", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File1231"), + Checksums: []common.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983c", Algorithm: common.SHA1}}, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{"Apache-2.0"}, FileCopyrightText: "Copyright (c) Jane Doe", } - f2 := &spdx.File2_1{ + f2 := &v2_1.File{ FileName: "/tmp/whatever2.txt", - FileSPDXIdentifier: spdx.ElementID("File1232"), - Checksums: []spdx.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983d", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File1232"), + Checksums: []common.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983d", Algorithm: common.SHA1}}, LicenseConcluded: "MIT", LicenseInfoInFiles: []string{"MIT"}, FileCopyrightText: "Copyright (c) John Doe", } - unFiles := []*spdx.File2_1{ + unFiles := []*v2_1.File{ f1, f2, } // Package 1: packaged files with snippets - sn1 := &spdx.Snippet2_1{ + sn1 := &v2_1.Snippet{ SnippetSPDXIdentifier: "Snippet19", - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "FileHasSnippets").ElementRefID, - Ranges: []spdx.SnippetRange{{StartPointer: spdx.SnippetRangePointer{Offset: 17}, EndPointer: spdx.SnippetRangePointer{Offset: 209}}}, + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "FileHasSnippets").ElementRefID, + Ranges: []common.SnippetRange{{StartPointer: common.SnippetRangePointer{Offset: 17}, EndPointer: common.SnippetRangePointer{Offset: 209}}}, SnippetLicenseConcluded: "GPL-2.0-or-later", SnippetCopyrightText: "Copyright (c) John Doe 20x6", } - sn2 := &spdx.Snippet2_1{ + sn2 := &v2_1.Snippet{ SnippetSPDXIdentifier: "Snippet20", - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "FileHasSnippets").ElementRefID, - Ranges: []spdx.SnippetRange{{StartPointer: spdx.SnippetRangePointer{Offset: 268}, EndPointer: spdx.SnippetRangePointer{Offset: 309}}}, + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "FileHasSnippets").ElementRefID, + Ranges: []common.SnippetRange{{StartPointer: common.SnippetRangePointer{Offset: 268}, EndPointer: common.SnippetRangePointer{Offset: 309}}}, SnippetLicenseConcluded: "WTFPL", SnippetCopyrightText: "NOASSERTION", } - f3 := &spdx.File2_1{ + f3 := &v2_1.File{ FileName: "/tmp/file-with-snippets.txt", - FileSPDXIdentifier: spdx.ElementID("FileHasSnippets"), - Checksums: []spdx.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983e", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("FileHasSnippets"), + Checksums: []common.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983e", Algorithm: common.SHA1}}, LicenseConcluded: "GPL-2.0-or-later AND WTFPL", LicenseInfoInFiles: []string{ "Apache-2.0", @@ -72,28 +73,28 @@ func TestSaver2_1DocumentSavesText(t *testing.T) { "WTFPL", }, FileCopyrightText: "Copyright (c) Jane Doe", - Snippets: map[spdx.ElementID]*spdx.Snippet2_1{ - spdx.ElementID("Snippet19"): sn1, - spdx.ElementID("Snippet20"): sn2, + Snippets: map[common.ElementID]*v2_1.Snippet{ + common.ElementID("Snippet19"): sn1, + common.ElementID("Snippet20"): sn2, }, } - f4 := &spdx.File2_1{ + f4 := &v2_1.File{ FileName: "/tmp/another-file.txt", - FileSPDXIdentifier: spdx.ElementID("FileAnother"), - Checksums: []spdx.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983f", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("FileAnother"), + Checksums: []common.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983f", Algorithm: common.SHA1}}, LicenseConcluded: "BSD-3-Clause", LicenseInfoInFiles: []string{"BSD-3-Clause"}, FileCopyrightText: "Copyright (c) Jane Doe LLC", } - pkgWith := &spdx.Package2_1{ + pkgWith := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, - PackageVerificationCode: spdx.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, + PackageVerificationCode: common.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, PackageLicenseConcluded: "GPL-2.0-or-later AND BSD-3-Clause AND WTFPL", PackageLicenseInfoFromFiles: []string{ "Apache-2.0", @@ -103,14 +104,14 @@ func TestSaver2_1DocumentSavesText(t *testing.T) { }, PackageLicenseDeclared: "Apache-2.0 OR GPL-2.0-or-later", PackageCopyrightText: "Copyright (c) John Doe, Inc.", - Files: []*spdx.File2_1{ + Files: []*v2_1.File{ f3, f4, }, } // Other Licenses 1 and 2 - ol1 := &spdx.OtherLicense2_1{ + ol1 := &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-1", ExtractedText: `License 1 text blah blah blah @@ -118,57 +119,57 @@ blah blah blah blah`, LicenseName: "License 1", } - ol2 := &spdx.OtherLicense2_1{ + ol2 := &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-2", ExtractedText: `License 2 text - this is a license that does some stuff`, LicenseName: "License 2", } // Relationships - rln1 := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p1"), + rln1 := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p1"), Relationship: "DESCRIBES", } - rln2 := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "File1231"), + rln2 := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "File1231"), Relationship: "DESCRIBES", } - rln3 := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "File1232"), + rln3 := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "File1232"), Relationship: "DESCRIBES", } // Annotations - ann1 := &spdx.Annotation2_1{ - Annotator: spdx.Annotator{Annotator: "John Doe", + ann1 := &v2_1.Annotation{ + Annotator: common.Annotator{Annotator: "John Doe", AnnotatorType: "Person"}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "DOCUMENT"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "DOCUMENT"), AnnotationComment: "This is an annotation about the SPDX document", } - ann2 := &spdx.Annotation2_1{ - Annotator: spdx.Annotator{Annotator: "John Doe, Inc.", + ann2 := &v2_1.Annotation{ + Annotator: common.Annotator{Annotator: "John Doe, Inc.", AnnotatorType: "Organization"}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "p1"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "p1"), AnnotationComment: "This is an annotation about Package p1", } // Reviews - rev1 := &spdx.Review2_1{ + rev1 := &v2_1.Review{ Reviewer: "John Doe", ReviewerType: "Person", ReviewDate: "2018-10-14T10:28:00Z", } - rev2 := &spdx.Review2_1{ + rev2 := &v2_1.Review{ Reviewer: "Jane Doe LLC", ReviewerType: "Organization", ReviewDate: "2018-10-14T10:28:00Z", @@ -176,31 +177,31 @@ blah blah blah blah`, } // now, build the document - doc := &spdx.Document2_1{ + doc := &v2_1.Document{ SPDXVersion: "SPDX-2.1", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), + SPDXIdentifier: common.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", CreationInfo: ci, - Packages: []*spdx.Package2_1{ + Packages: []*v2_1.Package{ pkgWith, }, Files: unFiles, - OtherLicenses: []*spdx.OtherLicense2_1{ + OtherLicenses: []*v2_1.OtherLicense{ ol1, ol2, }, - Relationships: []*spdx.Relationship2_1{ + Relationships: []*v2_1.Relationship{ rln1, rln2, rln3, }, - Annotations: []*spdx.Annotation2_1{ + Annotations: []*v2_1.Annotation{ ann1, ann2, }, - Reviews: []*spdx.Review2_1{ + Reviews: []*v2_1.Review{ rev1, rev2, }, @@ -332,7 +333,7 @@ ReviewComment: I have reviewed this SPDX document and it is awesome } func TestSaver2_1DocumentReturnsErrorIfNilCreationInfo(t *testing.T) { - doc := &spdx.Document2_1{} + doc := &v2_1.Document{} var got bytes.Buffer err := RenderDocument2_1(doc, &got) diff --git a/tvsaver/saver2v1/save_file.go b/tvsaver/saver2v1/save_file.go index c1311220..3cb90277 100644 --- a/tvsaver/saver2v1/save_file.go +++ b/tvsaver/saver2v1/save_file.go @@ -7,15 +7,16 @@ import ( "io" "sort" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderFile2_1(f *spdx.File2_1, w io.Writer) error { +func renderFile2_1(f *v2_1.File, w io.Writer) error { if f.FileName != "" { fmt.Fprintf(w, "FileName: %s\n", f.FileName) } if f.FileSPDXIdentifier != "" { - fmt.Fprintf(w, "SPDXID: %s\n", spdx.RenderElementID(f.FileSPDXIdentifier)) + fmt.Fprintf(w, "SPDXID: %s\n", common.RenderElementID(f.FileSPDXIdentifier)) } for _, s := range f.FileTypes { fmt.Fprintf(w, "FileType: %s\n", s) @@ -68,7 +69,7 @@ func renderFile2_1(f *spdx.File2_1, w io.Writer) error { } sort.Strings(snippetKeys) for _, sID := range snippetKeys { - s := f.Snippets[spdx.ElementID(sID)] + s := f.Snippets[common.ElementID(sID)] renderSnippet2_1(s, w) } diff --git a/tvsaver/saver2v1/save_file_test.go b/tvsaver/saver2v1/save_file_test.go index 97084304..ba1d82b3 100644 --- a/tvsaver/saver2v1/save_file_test.go +++ b/tvsaver/saver2v1/save_file_test.go @@ -6,22 +6,23 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== File section Saver tests ===== func TestSaver2_1FileSavesText(t *testing.T) { - f := &spdx.File2_1{ + f := &v2_1.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), + FileSPDXIdentifier: common.ElementID("File123"), FileTypes: []string{ "TEXT", "DOCUMENTATION", }, - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, - {Algorithm: spdx.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd"}, - {Algorithm: spdx.MD5, Value: "624c1abb3664f4b35547e7c73864ad24"}, + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + {Algorithm: common.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd"}, + {Algorithm: common.MD5, Value: "624c1abb3664f4b35547e7c73864ad24"}, }, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ @@ -30,20 +31,20 @@ func TestSaver2_1FileSavesText(t *testing.T) { }, LicenseComments: "this is a license comment(s)", FileCopyrightText: "Copyright (c) Jane Doe", - ArtifactOfProjects: []*spdx.ArtifactOfProject2_1{ - &spdx.ArtifactOfProject2_1{ + ArtifactOfProjects: []*v2_1.ArtifactOfProject{ + &v2_1.ArtifactOfProject{ Name: "project1", HomePage: "http://example.com/1/", URI: "http://example.com/1/uri.whatever", }, - &spdx.ArtifactOfProject2_1{ + &v2_1.ArtifactOfProject{ Name: "project2", }, - &spdx.ArtifactOfProject2_1{ + &v2_1.ArtifactOfProject{ Name: "project3", HomePage: "http://example.com/3/", }, - &spdx.ArtifactOfProject2_1{ + &v2_1.ArtifactOfProject{ Name: "project4", URI: "http://example.com/4/uri.whatever", }, @@ -105,32 +106,32 @@ FileDependency: g.txt } func TestSaver2_1FileSavesSnippetsAlso(t *testing.T) { - sn1 := &spdx.Snippet2_1{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet19"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File123").ElementRefID, - Ranges: []spdx.SnippetRange{{StartPointer: spdx.SnippetRangePointer{Offset: 17}, EndPointer: spdx.SnippetRangePointer{Offset: 209}}}, + sn1 := &v2_1.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet19"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File123").ElementRefID, + Ranges: []common.SnippetRange{{StartPointer: common.SnippetRangePointer{Offset: 17}, EndPointer: common.SnippetRangePointer{Offset: 209}}}, SnippetLicenseConcluded: "GPL-2.0-or-later", SnippetCopyrightText: "Copyright (c) John Doe 20x6", } - sn2 := &spdx.Snippet2_1{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet20"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File123").ElementRefID, - Ranges: []spdx.SnippetRange{{StartPointer: spdx.SnippetRangePointer{Offset: 268}, EndPointer: spdx.SnippetRangePointer{Offset: 309}}}, + sn2 := &v2_1.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet20"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File123").ElementRefID, + Ranges: []common.SnippetRange{{StartPointer: common.SnippetRangePointer{Offset: 268}, EndPointer: common.SnippetRangePointer{Offset: 309}}}, SnippetLicenseConcluded: "WTFPL", SnippetCopyrightText: "NOASSERTION", } - sns := map[spdx.ElementID]*spdx.Snippet2_1{ - spdx.ElementID("Snippet19"): sn1, - spdx.ElementID("Snippet20"): sn2, + sns := map[common.ElementID]*v2_1.Snippet{ + common.ElementID("Snippet19"): sn1, + common.ElementID("Snippet20"): sn2, } - f := &spdx.File2_1{ + f := &v2_1.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + FileSPDXIdentifier: common.ElementID("File123"), + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, }, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ @@ -177,11 +178,11 @@ SnippetCopyrightText: NOASSERTION } func TestSaver2_1FileOmitsOptionalFieldsIfEmpty(t *testing.T) { - f := &spdx.File2_1{ + f := &v2_1.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + FileSPDXIdentifier: common.ElementID("File123"), + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, }, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ @@ -215,11 +216,11 @@ FileCopyrightText: Copyright (c) Jane Doe } func TestSaver2_1FileWrapsCopyrightMultiLine(t *testing.T) { - f := &spdx.File2_1{ + f := &v2_1.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + FileSPDXIdentifier: common.ElementID("File123"), + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, }, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ @@ -255,11 +256,11 @@ Copyright (c) John Doe } func TestSaver2_1FileWrapsCommentsAndNoticesMultiLine(t *testing.T) { - f := &spdx.File2_1{ + f := &v2_1.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + FileSPDXIdentifier: common.ElementID("File123"), + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, }, LicenseComments: `this is a multi-line license comment`, diff --git a/tvsaver/saver2v1/save_other_license.go b/tvsaver/saver2v1/save_other_license.go index ea48b807..b30aecf1 100644 --- a/tvsaver/saver2v1/save_other_license.go +++ b/tvsaver/saver2v1/save_other_license.go @@ -6,10 +6,10 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderOtherLicense2_1(ol *spdx.OtherLicense2_1, w io.Writer) error { +func renderOtherLicense2_1(ol *v2_1.OtherLicense, w io.Writer) error { if ol.LicenseIdentifier != "" { fmt.Fprintf(w, "LicenseID: %s\n", ol.LicenseIdentifier) } diff --git a/tvsaver/saver2v1/save_other_license_test.go b/tvsaver/saver2v1/save_other_license_test.go index 5feb96ee..46ef82cd 100644 --- a/tvsaver/saver2v1/save_other_license_test.go +++ b/tvsaver/saver2v1/save_other_license_test.go @@ -6,12 +6,12 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Other License section Saver tests ===== func TestSaver2_1OtherLicenseSavesText(t *testing.T) { - ol := &spdx.OtherLicense2_1{ + ol := &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-1", ExtractedText: `License 1 text blah blah blah @@ -51,7 +51,7 @@ LicenseComment: this is a license comment } func TestSaver2_1OtherLicenseOmitsOptionalFieldsIfEmpty(t *testing.T) { - ol := &spdx.OtherLicense2_1{ + ol := &v2_1.OtherLicense{ LicenseIdentifier: "LicenseRef-1", ExtractedText: `License 1 text blah blah blah diff --git a/tvsaver/saver2v1/save_package.go b/tvsaver/saver2v1/save_package.go index 24a468c0..762876f2 100644 --- a/tvsaver/saver2v1/save_package.go +++ b/tvsaver/saver2v1/save_package.go @@ -8,15 +8,16 @@ import ( "sort" "strings" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderPackage2_1(pkg *spdx.Package2_1, w io.Writer) error { +func renderPackage2_1(pkg *v2_1.Package, w io.Writer) error { if pkg.PackageName != "" { fmt.Fprintf(w, "PackageName: %s\n", pkg.PackageName) } if pkg.PackageSPDXIdentifier != "" { - fmt.Fprintf(w, "SPDXID: %s\n", spdx.RenderElementID(pkg.PackageSPDXIdentifier)) + fmt.Fprintf(w, "SPDXID: %s\n", common.RenderElementID(pkg.PackageSPDXIdentifier)) } if pkg.PackageVersion != "" { fmt.Fprintf(w, "PackageVersion: %s\n", pkg.PackageVersion) diff --git a/tvsaver/saver2v1/save_package_test.go b/tvsaver/saver2v1/save_package_test.go index 0f1541ca..4939b3fe 100644 --- a/tvsaver/saver2v1/save_package_test.go +++ b/tvsaver/saver2v1/save_package_test.go @@ -6,7 +6,8 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Package section Saver tests ===== @@ -17,7 +18,7 @@ func TestSaver2_1PackageSavesTextCombo1(t *testing.T) { // PackageVerificationCodeExcludedFile has string // NOTE, this is an entirely made up CPE and the format is likely invalid - per1 := &spdx.PackageExternalReference2_1{ + per1 := &v2_1.PackageExternalReference{ Category: "SECURITY", RefType: "cpe22Type", Locator: "cpe:/a:john_doe_inc:p1:0.1.0", @@ -25,7 +26,7 @@ func TestSaver2_1PackageSavesTextCombo1(t *testing.T) { } // NOTE, this is an entirely made up NPM - per2 := &spdx.PackageExternalReference2_1{ + per2 := &v2_1.PackageExternalReference{ Category: "PACKAGE-MANAGER", RefType: "npm", Locator: "p1@0.1.0", @@ -33,38 +34,38 @@ func TestSaver2_1PackageSavesTextCombo1(t *testing.T) { multi-line external ref comment`, } - per3 := &spdx.PackageExternalReference2_1{ + per3 := &v2_1.PackageExternalReference{ Category: "OTHER", RefType: "anything", Locator: "anything-without-spaces-can-go-here", // no ExternalRefComment for this one } - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageVersion: "0.1.0", PackageFileName: "p1-0.1.0-master.tar.gz", - PackageSupplier: &spdx.Supplier{SupplierType: "Organization", Supplier: "John Doe, Inc."}, - PackageOriginator: &spdx.Originator{Originator: "John Doe", OriginatorType: "Person"}, + PackageSupplier: &common.Supplier{SupplierType: "Organization", Supplier: "John Doe, Inc."}, + PackageOriginator: &common.Originator{Originator: "John Doe", OriginatorType: "Person"}, PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, - PackageVerificationCode: spdx.PackageVerificationCode{ + PackageVerificationCode: common.PackageVerificationCode{ Value: "0123456789abcdef0123456789abcdef01234567", ExcludedFiles: []string{"p1-0.1.0.spdx"}, }, - PackageChecksums: []spdx.Checksum{ + PackageChecksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c", }, { - Algorithm: spdx.SHA256, + Algorithm: common.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd", }, { - Algorithm: spdx.MD5, + Algorithm: common.MD5, Value: "624c1abb3664f4b35547e7c73864ad24", }, }, @@ -82,7 +83,7 @@ multi-line external ref comment`, PackageSummary: "this is a summary comment", PackageDescription: "this is a description comment", PackageComment: "this is a comment comment", - PackageExternalReferences: []*spdx.PackageExternalReference2_1{ + PackageExternalReferences: []*v2_1.PackageExternalReference{ per1, per2, per3, @@ -143,28 +144,28 @@ func TestSaver2_1PackageSavesTextCombo2(t *testing.T) { // FilesAnalyzed true, IsFilesAnalyzedTagPresent false // PackageVerificationCodeExcludedFile is empty - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageVersion: "0.1.0", PackageFileName: "p1-0.1.0-master.tar.gz", - PackageSupplier: &spdx.Supplier{Supplier: "NOASSERTION"}, - PackageOriginator: &spdx.Originator{OriginatorType: "Organization", Originator: "John Doe, Inc."}, + PackageSupplier: &common.Supplier{Supplier: "NOASSERTION"}, + PackageOriginator: &common.Originator{OriginatorType: "Organization", Originator: "John Doe, Inc."}, PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: false, - PackageVerificationCode: spdx.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, - PackageChecksums: []spdx.Checksum{ + PackageVerificationCode: common.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, + PackageChecksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c", }, { - Algorithm: spdx.SHA256, + Algorithm: common.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd", }, { - Algorithm: spdx.MD5, + Algorithm: common.MD5, Value: "624c1abb3664f4b35547e7c73864ad24", }, }, @@ -231,30 +232,30 @@ func TestSaver2_1PackageSavesTextCombo3(t *testing.T) { // FilesAnalyzed false, IsFilesAnalyzedTagPresent true // PackageVerificationCodeExcludedFile is empty - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageVersion: "0.1.0", PackageFileName: "p1-0.1.0-master.tar.gz", - PackageSupplier: &spdx.Supplier{Supplier: "John Doe", SupplierType: "Person"}, - PackageOriginator: &spdx.Originator{Originator: "NOASSERTION"}, + PackageSupplier: &common.Supplier{Supplier: "John Doe", SupplierType: "Person"}, + PackageOriginator: &common.Originator{Originator: "NOASSERTION"}, PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: false, IsFilesAnalyzedTagPresent: true, // NOTE that verification code MUST be omitted from output // since FilesAnalyzed is false - PackageVerificationCode: spdx.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, - PackageChecksums: []spdx.Checksum{ + PackageVerificationCode: common.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, + PackageChecksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c", }, { - Algorithm: spdx.SHA256, + Algorithm: common.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd", }, { - Algorithm: spdx.MD5, + Algorithm: common.MD5, Value: "624c1abb3664f4b35547e7c73864ad24", }, }, @@ -315,9 +316,9 @@ PackageComment: this is a comment comment } func TestSaver2_1PackageSaveOmitsOptionalFieldsIfEmpty(t *testing.T) { - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: false, IsFilesAnalyzedTagPresent: true, @@ -361,12 +362,12 @@ PackageCopyrightText: Copyright (c) John Doe, Inc. } func TestSaver2_1PackageSavesFilesIfPresent(t *testing.T) { - f1 := &spdx.File2_1{ + f1 := &v2_1.File{ FileName: "/tmp/whatever1.txt", - FileSPDXIdentifier: spdx.ElementID("File1231"), - Checksums: []spdx.Checksum{ + FileSPDXIdentifier: common.ElementID("File1231"), + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c", }, }, @@ -375,12 +376,12 @@ func TestSaver2_1PackageSavesFilesIfPresent(t *testing.T) { FileCopyrightText: "Copyright (c) Jane Doe", } - f2 := &spdx.File2_1{ + f2 := &v2_1.File{ FileName: "/tmp/whatever2.txt", - FileSPDXIdentifier: spdx.ElementID("File1232"), - Checksums: []spdx.Checksum{ + FileSPDXIdentifier: common.ElementID("File1232"), + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983d", }, }, @@ -389,9 +390,9 @@ func TestSaver2_1PackageSavesFilesIfPresent(t *testing.T) { FileCopyrightText: "Copyright (c) John Doe", } - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: false, IsFilesAnalyzedTagPresent: true, @@ -407,7 +408,7 @@ func TestSaver2_1PackageSavesFilesIfPresent(t *testing.T) { }, PackageLicenseDeclared: "Apache-2.0 OR GPL-2.0-or-later", PackageCopyrightText: "Copyright (c) John Doe, Inc.", - Files: []*spdx.File2_1{ + Files: []*v2_1.File{ f1, f2, }, @@ -453,9 +454,9 @@ FileCopyrightText: Copyright (c) John Doe } func TestSaver2_1PackageWrapsCopyrightMultiLine(t *testing.T) { - pkg := &spdx.Package2_1{ + pkg := &v2_1.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: false, IsFilesAnalyzedTagPresent: true, diff --git a/tvsaver/saver2v1/save_relationship.go b/tvsaver/saver2v1/save_relationship.go index aea48bc3..01aa3dde 100644 --- a/tvsaver/saver2v1/save_relationship.go +++ b/tvsaver/saver2v1/save_relationship.go @@ -6,12 +6,13 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderRelationship2_1(rln *spdx.Relationship2_1, w io.Writer) error { - rlnAStr := spdx.RenderDocElementID(rln.RefA) - rlnBStr := spdx.RenderDocElementID(rln.RefB) +func renderRelationship2_1(rln *v2_1.Relationship, w io.Writer) error { + rlnAStr := common.RenderDocElementID(rln.RefA) + rlnBStr := common.RenderDocElementID(rln.RefB) if rlnAStr != "SPDXRef-" && rlnBStr != "SPDXRef-" && rln.Relationship != "" { fmt.Fprintf(w, "Relationship: %s %s %s\n", rlnAStr, rln.Relationship, rlnBStr) } diff --git a/tvsaver/saver2v1/save_relationship_test.go b/tvsaver/saver2v1/save_relationship_test.go index 6fa03bd7..886670b4 100644 --- a/tvsaver/saver2v1/save_relationship_test.go +++ b/tvsaver/saver2v1/save_relationship_test.go @@ -6,14 +6,15 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Relationship section Saver tests ===== func TestSaver2_1RelationshipSavesText(t *testing.T) { - rln := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "2"), + rln := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "2"), Relationship: "DESCRIBES", RelationshipComment: "this is a comment", } @@ -39,9 +40,9 @@ RelationshipComment: this is a comment } func TestSaver2_1RelationshipOmitsOptionalFieldsIfEmpty(t *testing.T) { - rln := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "2"), + rln := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "2"), Relationship: "DESCRIBES", } @@ -64,9 +65,9 @@ func TestSaver2_1RelationshipOmitsOptionalFieldsIfEmpty(t *testing.T) { } func TestSaver2_1RelationshipWrapsCommentMultiLine(t *testing.T) { - rln := &spdx.Relationship2_1{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "2"), + rln := &v2_1.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "2"), Relationship: "DESCRIBES", RelationshipComment: `this is a multi-line comment`, diff --git a/tvsaver/saver2v1/save_review.go b/tvsaver/saver2v1/save_review.go index 31939631..33511a36 100644 --- a/tvsaver/saver2v1/save_review.go +++ b/tvsaver/saver2v1/save_review.go @@ -6,10 +6,10 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderReview2_1(rev *spdx.Review2_1, w io.Writer) error { +func renderReview2_1(rev *v2_1.Review, w io.Writer) error { if rev.Reviewer != "" && rev.ReviewerType != "" { fmt.Fprintf(w, "Reviewer: %s: %s\n", rev.ReviewerType, rev.Reviewer) } diff --git a/tvsaver/saver2v1/save_review_test.go b/tvsaver/saver2v1/save_review_test.go index 74216815..10d030b9 100644 --- a/tvsaver/saver2v1/save_review_test.go +++ b/tvsaver/saver2v1/save_review_test.go @@ -6,12 +6,12 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Review section Saver tests ===== func TestSaver2_1ReviewSavesText(t *testing.T) { - rev := &spdx.Review2_1{ + rev := &v2_1.Review{ Reviewer: "John Doe", ReviewerType: "Person", ReviewDate: "2018-10-14T10:28:00Z", @@ -40,7 +40,7 @@ ReviewComment: this is a review comment } func TestSaver2_1ReviewOmitsOptionalFieldsIfEmpty(t *testing.T) { - rev := &spdx.Review2_1{ + rev := &v2_1.Review{ Reviewer: "John Doe", ReviewerType: "Person", ReviewDate: "2018-10-14T10:28:00Z", @@ -67,7 +67,7 @@ ReviewDate: 2018-10-14T10:28:00Z } func TestSaver2_1ReviewWrapsMultiLine(t *testing.T) { - rev := &spdx.Review2_1{ + rev := &v2_1.Review{ Reviewer: "John Doe", ReviewerType: "Person", ReviewDate: "2018-10-14T10:28:00Z", diff --git a/tvsaver/saver2v1/save_snippet.go b/tvsaver/saver2v1/save_snippet.go index 13995489..19c93230 100644 --- a/tvsaver/saver2v1/save_snippet.go +++ b/tvsaver/saver2v1/save_snippet.go @@ -6,14 +6,15 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) -func renderSnippet2_1(sn *spdx.Snippet2_1, w io.Writer) error { +func renderSnippet2_1(sn *v2_1.Snippet, w io.Writer) error { if sn.SnippetSPDXIdentifier != "" { - fmt.Fprintf(w, "SnippetSPDXID: %s\n", spdx.RenderElementID(sn.SnippetSPDXIdentifier)) + fmt.Fprintf(w, "SnippetSPDXID: %s\n", common.RenderElementID(sn.SnippetSPDXIdentifier)) } - snFromFileIDStr := spdx.RenderElementID(sn.SnippetFromFileSPDXIdentifier) + snFromFileIDStr := common.RenderElementID(sn.SnippetFromFileSPDXIdentifier) if snFromFileIDStr != "" { fmt.Fprintf(w, "SnippetFromFileSPDXID: %s\n", snFromFileIDStr) } diff --git a/tvsaver/saver2v1/save_snippet_test.go b/tvsaver/saver2v1/save_snippet_test.go index fd6357ec..3c9036a0 100644 --- a/tvsaver/saver2v1/save_snippet_test.go +++ b/tvsaver/saver2v1/save_snippet_test.go @@ -6,22 +6,23 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" ) // ===== Snippet section Saver tests ===== func TestSaver2_1SnippetSavesText(t *testing.T) { - sn := &spdx.Snippet2_1{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet17"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292").ElementRefID, - Ranges: []spdx.SnippetRange{ + sn := &v2_1.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet17"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File292").ElementRefID, + Ranges: []common.SnippetRange{ { - StartPointer: spdx.SnippetRangePointer{LineNumber: 3}, - EndPointer: spdx.SnippetRangePointer{LineNumber: 8}, + StartPointer: common.SnippetRangePointer{LineNumber: 3}, + EndPointer: common.SnippetRangePointer{LineNumber: 8}, }, { - StartPointer: spdx.SnippetRangePointer{Offset: 17}, - EndPointer: spdx.SnippetRangePointer{Offset: 209}, + StartPointer: common.SnippetRangePointer{Offset: 17}, + EndPointer: common.SnippetRangePointer{Offset: 209}, }, }, SnippetLicenseConcluded: "GPL-2.0-or-later", @@ -65,13 +66,13 @@ SnippetName: from John's program } func TestSaver2_1SnippetOmitsOptionalFieldsIfEmpty(t *testing.T) { - sn := &spdx.Snippet2_1{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet17"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292").ElementRefID, - Ranges: []spdx.SnippetRange{ + sn := &v2_1.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet17"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File292").ElementRefID, + Ranges: []common.SnippetRange{ { - StartPointer: spdx.SnippetRangePointer{Offset: 17}, - EndPointer: spdx.SnippetRangePointer{Offset: 209}, + StartPointer: common.SnippetRangePointer{Offset: 17}, + EndPointer: common.SnippetRangePointer{Offset: 209}, }, }, SnippetLicenseConcluded: "GPL-2.0-or-later", @@ -102,13 +103,13 @@ SnippetCopyrightText: Copyright (c) John Doe 20x6 } func TestSaver2_1SnippetWrapsCopyrightMultiline(t *testing.T) { - sn := &spdx.Snippet2_1{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet17"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292").ElementRefID, - Ranges: []spdx.SnippetRange{ + sn := &v2_1.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet17"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File292").ElementRefID, + Ranges: []common.SnippetRange{ { - StartPointer: spdx.SnippetRangePointer{Offset: 17}, - EndPointer: spdx.SnippetRangePointer{Offset: 209}, + StartPointer: common.SnippetRangePointer{Offset: 17}, + EndPointer: common.SnippetRangePointer{Offset: 209}, }, }, SnippetLicenseConcluded: "GPL-2.0-or-later", diff --git a/tvsaver/saver2v2/save_annotation.go b/tvsaver/saver2v2/save_annotation.go index ddfe483a..f5ea8931 100644 --- a/tvsaver/saver2v2/save_annotation.go +++ b/tvsaver/saver2v2/save_annotation.go @@ -6,10 +6,11 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) -func renderAnnotation2_2(ann *spdx.Annotation2_2, w io.Writer) error { +func renderAnnotation2_2(ann *v2_2.Annotation, w io.Writer) error { if ann.Annotator.Annotator != "" && ann.Annotator.AnnotatorType != "" { fmt.Fprintf(w, "Annotator: %s: %s\n", ann.Annotator.AnnotatorType, ann.Annotator.Annotator) } @@ -19,7 +20,7 @@ func renderAnnotation2_2(ann *spdx.Annotation2_2, w io.Writer) error { if ann.AnnotationType != "" { fmt.Fprintf(w, "AnnotationType: %s\n", ann.AnnotationType) } - annIDStr := spdx.RenderDocElementID(ann.AnnotationSPDXIdentifier) + annIDStr := common.RenderDocElementID(ann.AnnotationSPDXIdentifier) if annIDStr != "SPDXRef-" { fmt.Fprintf(w, "SPDXREF: %s\n", annIDStr) } diff --git a/tvsaver/saver2v2/save_annotation_test.go b/tvsaver/saver2v2/save_annotation_test.go index 46d8546b..e8d1741a 100644 --- a/tvsaver/saver2v2/save_annotation_test.go +++ b/tvsaver/saver2v2/save_annotation_test.go @@ -6,16 +6,17 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Annotation section Saver tests ===== func TestSaver2_2AnnotationSavesTextForPerson(t *testing.T) { - ann := &spdx.Annotation2_2{ - Annotator: spdx.Annotator{AnnotatorType: "Person", Annotator: "John Doe"}, + ann := &v2_2.Annotation{ + Annotator: common.Annotator{AnnotatorType: "Person", Annotator: "John Doe"}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "DOCUMENT"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "DOCUMENT"), AnnotationComment: "This is an annotation about the SPDX document", } @@ -43,11 +44,11 @@ AnnotationComment: This is an annotation about the SPDX document } func TestSaver2_2AnnotationSavesTextForOrganization(t *testing.T) { - ann := &spdx.Annotation2_2{ - Annotator: spdx.Annotator{AnnotatorType: "Organization", Annotator: "John Doe, Inc."}, + ann := &v2_2.Annotation{ + Annotator: common.Annotator{AnnotatorType: "Organization", Annotator: "John Doe, Inc."}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "DOCUMENT"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "DOCUMENT"), AnnotationComment: "This is an annotation about the SPDX document", } @@ -75,11 +76,11 @@ AnnotationComment: This is an annotation about the SPDX document } func TestSaver2_2AnnotationSavesTextForTool(t *testing.T) { - ann := &spdx.Annotation2_2{ - Annotator: spdx.Annotator{AnnotatorType: "Tool", Annotator: "magictool-1.1"}, + ann := &v2_2.Annotation{ + Annotator: common.Annotator{AnnotatorType: "Tool", Annotator: "magictool-1.1"}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "DOCUMENT"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "DOCUMENT"), AnnotationComment: "This is an annotation about the SPDX document", } diff --git a/tvsaver/saver2v2/save_creation_info.go b/tvsaver/saver2v2/save_creation_info.go index df2b0b0f..87533a2a 100644 --- a/tvsaver/saver2v2/save_creation_info.go +++ b/tvsaver/saver2v2/save_creation_info.go @@ -4,11 +4,12 @@ package saver2v2 import ( "fmt" - "github.com/spdx/tools-golang/spdx" "io" + + "github.com/spdx/tools-golang/spdx/v2_2" ) -func renderCreationInfo2_2(ci *spdx.CreationInfo2_2, w io.Writer) error { +func renderCreationInfo2_2(ci *v2_2.CreationInfo, w io.Writer) error { 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 ba3c18d8..bb10aa37 100644 --- a/tvsaver/saver2v2/save_creation_info_test.go +++ b/tvsaver/saver2v2/save_creation_info_test.go @@ -6,14 +6,15 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Creation Info section Saver tests ===== func TestSaver2_2CISavesText(t *testing.T) { - ci := &spdx.CreationInfo2_2{ + ci := &v2_2.CreationInfo{ LicenseListVersion: "3.9", - Creators: []spdx.Creator{ + Creators: []common.Creator{ {Creator: "John Doe", CreatorType: "Person"}, {Creator: "Jane Doe (janedoe@example.com)", CreatorType: "Person"}, {Creator: "John Doe, Inc.", CreatorType: "Organization"}, @@ -56,8 +57,8 @@ CreatorComment: this is a creator comment func TestSaver2_2CIOmitsOptionalFieldsIfEmpty(t *testing.T) { // --- need at least one creator; do first for Persons --- - ci1 := &spdx.CreationInfo2_2{ - Creators: []spdx.Creator{ + ci1 := &v2_2.CreationInfo{ + Creators: []common.Creator{ {Creator: "John Doe", CreatorType: "Person"}, }, Created: "2018-10-10T06:20:00Z", @@ -83,8 +84,8 @@ Created: 2018-10-10T06:20:00Z } // --- need at least one creator; now switch to organization --- - ci2 := &spdx.CreationInfo2_2{ - Creators: []spdx.Creator{ + ci2 := &v2_2.CreationInfo{ + Creators: []common.Creator{ {Creator: "John Doe, Inc.", CreatorType: "Organization"}, }, Created: "2018-10-10T06:20:00Z", diff --git a/tvsaver/saver2v2/save_document.go b/tvsaver/saver2v2/save_document.go index 04b482da..efec2a1e 100644 --- a/tvsaver/saver2v2/save_document.go +++ b/tvsaver/saver2v2/save_document.go @@ -9,14 +9,15 @@ import ( "io" "sort" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // RenderDocument2_2 is the main entry point to take an SPDX in-memory // Document (version 2.2), and render it to the received io.Writer. // It is only exported in order to be available to the tvsaver package, // and typically does not need to be called by client code. -func RenderDocument2_2(doc *spdx.Document2_2, w io.Writer) error { +func RenderDocument2_2(doc *v2_2.Document, w io.Writer) error { if doc.CreationInfo == nil { return fmt.Errorf("Document had nil CreationInfo section") } @@ -28,7 +29,7 @@ func RenderDocument2_2(doc *spdx.Document2_2, w io.Writer) error { fmt.Fprintf(w, "DataLicense: %s\n", doc.DataLicense) } if doc.SPDXIdentifier != "" { - fmt.Fprintf(w, "SPDXID: %s\n", spdx.RenderElementID(doc.SPDXIdentifier)) + fmt.Fprintf(w, "SPDXID: %s\n", common.RenderElementID(doc.SPDXIdentifier)) } if doc.DocumentName != "" { fmt.Fprintf(w, "DocumentName: %s\n", doc.DocumentName) diff --git a/tvsaver/saver2v2/save_document_test.go b/tvsaver/saver2v2/save_document_test.go index 552cdab5..39146dd0 100644 --- a/tvsaver/saver2v2/save_document_test.go +++ b/tvsaver/saver2v2/save_document_test.go @@ -6,65 +6,66 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== entire Document Saver tests ===== func TestSaver2_2DocumentSavesText(t *testing.T) { // Creation Info section - ci := &spdx.CreationInfo2_2{ - Creators: []spdx.Creator{ + ci := &v2_2.CreationInfo{ + Creators: []common.Creator{ {Creator: "John Doe", CreatorType: "Person"}, }, Created: "2018-10-10T06:20:00Z", } // unpackaged files - f1 := &spdx.File2_2{ + f1 := &v2_2.File{ FileName: "/tmp/whatever1.txt", - FileSPDXIdentifier: spdx.ElementID("File1231"), - Checksums: []spdx.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983c", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File1231"), + Checksums: []common.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983c", Algorithm: common.SHA1}}, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{"Apache-2.0"}, FileCopyrightText: "Copyright (c) Jane Doe", } - f2 := &spdx.File2_2{ + f2 := &v2_2.File{ FileName: "/tmp/whatever2.txt", - FileSPDXIdentifier: spdx.ElementID("File1232"), - Checksums: []spdx.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983d", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("File1232"), + Checksums: []common.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983d", Algorithm: common.SHA1}}, LicenseConcluded: "MIT", LicenseInfoInFiles: []string{"MIT"}, FileCopyrightText: "Copyright (c) John Doe", } - unFiles := []*spdx.File2_2{ + unFiles := []*v2_2.File{ f1, f2, } // Package 1: packaged files with snippets - sn1 := &spdx.Snippet2_2{ + sn1 := &v2_2.Snippet{ SnippetSPDXIdentifier: "Snippet19", - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "FileHasSnippets").ElementRefID, - Ranges: []spdx.SnippetRange{{StartPointer: spdx.SnippetRangePointer{Offset: 17}, EndPointer: spdx.SnippetRangePointer{Offset: 209}}}, + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "FileHasSnippets").ElementRefID, + Ranges: []common.SnippetRange{{StartPointer: common.SnippetRangePointer{Offset: 17}, EndPointer: common.SnippetRangePointer{Offset: 209}}}, SnippetLicenseConcluded: "GPL-2.0-or-later", SnippetCopyrightText: "Copyright (c) John Doe 20x6", } - sn2 := &spdx.Snippet2_2{ + sn2 := &v2_2.Snippet{ SnippetSPDXIdentifier: "Snippet20", - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "FileHasSnippets").ElementRefID, - Ranges: []spdx.SnippetRange{{StartPointer: spdx.SnippetRangePointer{Offset: 268}, EndPointer: spdx.SnippetRangePointer{Offset: 309}}}, + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "FileHasSnippets").ElementRefID, + Ranges: []common.SnippetRange{{StartPointer: common.SnippetRangePointer{Offset: 268}, EndPointer: common.SnippetRangePointer{Offset: 309}}}, SnippetLicenseConcluded: "WTFPL", SnippetCopyrightText: "NOASSERTION", } - f3 := &spdx.File2_2{ + f3 := &v2_2.File{ FileName: "/tmp/file-with-snippets.txt", - FileSPDXIdentifier: spdx.ElementID("FileHasSnippets"), - Checksums: []spdx.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983e", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("FileHasSnippets"), + Checksums: []common.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983e", Algorithm: common.SHA1}}, LicenseConcluded: "GPL-2.0-or-later AND WTFPL", LicenseInfoInFiles: []string{ "Apache-2.0", @@ -72,28 +73,28 @@ func TestSaver2_2DocumentSavesText(t *testing.T) { "WTFPL", }, FileCopyrightText: "Copyright (c) Jane Doe", - Snippets: map[spdx.ElementID]*spdx.Snippet2_2{ - spdx.ElementID("Snippet19"): sn1, - spdx.ElementID("Snippet20"): sn2, + Snippets: map[common.ElementID]*v2_2.Snippet{ + common.ElementID("Snippet19"): sn1, + common.ElementID("Snippet20"): sn2, }, } - f4 := &spdx.File2_2{ + f4 := &v2_2.File{ FileName: "/tmp/another-file.txt", - FileSPDXIdentifier: spdx.ElementID("FileAnother"), - Checksums: []spdx.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983f", Algorithm: spdx.SHA1}}, + FileSPDXIdentifier: common.ElementID("FileAnother"), + Checksums: []common.Checksum{{Value: "85ed0817af83a24ad8da68c2b5094de69833983f", Algorithm: common.SHA1}}, LicenseConcluded: "BSD-3-Clause", LicenseInfoInFiles: []string{"BSD-3-Clause"}, FileCopyrightText: "Copyright (c) Jane Doe LLC", } - pkgWith := &spdx.Package2_2{ + pkgWith := &v2_2.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, - PackageVerificationCode: spdx.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, + PackageVerificationCode: common.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, PackageLicenseConcluded: "GPL-2.0-or-later AND BSD-3-Clause AND WTFPL", PackageLicenseInfoFromFiles: []string{ "Apache-2.0", @@ -103,14 +104,14 @@ func TestSaver2_2DocumentSavesText(t *testing.T) { }, PackageLicenseDeclared: "Apache-2.0 OR GPL-2.0-or-later", PackageCopyrightText: "Copyright (c) John Doe, Inc.", - Files: []*spdx.File2_2{ + Files: []*v2_2.File{ f3, f4, }, } // Other Licenses 1 and 2 - ol1 := &spdx.OtherLicense2_2{ + ol1 := &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-1", ExtractedText: `License 1 text blah blah blah @@ -118,57 +119,57 @@ blah blah blah blah`, LicenseName: "License 1", } - ol2 := &spdx.OtherLicense2_2{ + ol2 := &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-2", ExtractedText: `License 2 text - this is a license that does some stuff`, LicenseName: "License 2", } // Relationships - rln1 := &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "p1"), + rln1 := &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "p1"), Relationship: "DESCRIBES", } - rln2 := &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "File1231"), + rln2 := &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "File1231"), Relationship: "DESCRIBES", } - rln3 := &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "File1232"), + rln3 := &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "File1232"), Relationship: "DESCRIBES", } // Annotations - ann1 := &spdx.Annotation2_2{ - Annotator: spdx.Annotator{Annotator: "John Doe", + ann1 := &v2_2.Annotation{ + Annotator: common.Annotator{Annotator: "John Doe", AnnotatorType: "Person"}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "DOCUMENT"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "DOCUMENT"), AnnotationComment: "This is an annotation about the SPDX document", } - ann2 := &spdx.Annotation2_2{ - Annotator: spdx.Annotator{Annotator: "John Doe, Inc.", + ann2 := &v2_2.Annotation{ + Annotator: common.Annotator{Annotator: "John Doe, Inc.", AnnotatorType: "Organization"}, AnnotationDate: "2018-10-10T17:52:00Z", AnnotationType: "REVIEW", - AnnotationSPDXIdentifier: spdx.MakeDocElementID("", "p1"), + AnnotationSPDXIdentifier: common.MakeDocElementID("", "p1"), AnnotationComment: "This is an annotation about Package p1", } // Reviews - rev1 := &spdx.Review2_2{ + rev1 := &v2_2.Review{ Reviewer: "John Doe", ReviewerType: "Person", ReviewDate: "2018-10-14T10:28:00Z", } - rev2 := &spdx.Review2_2{ + rev2 := &v2_2.Review{ Reviewer: "Jane Doe LLC", ReviewerType: "Organization", ReviewDate: "2018-10-14T10:28:00Z", @@ -176,31 +177,31 @@ blah blah blah blah`, } // now, build the document - doc := &spdx.Document2_2{ + doc := &v2_2.Document{ SPDXVersion: "SPDX-2.2", DataLicense: "CC0-1.0", - SPDXIdentifier: spdx.ElementID("DOCUMENT"), + SPDXIdentifier: common.ElementID("DOCUMENT"), DocumentName: "tools-golang-0.0.1.abcdef", DocumentNamespace: "https://github.com/spdx/spdx-docs/tools-golang/tools-golang-0.0.1.abcdef.whatever", CreationInfo: ci, - Packages: []*spdx.Package2_2{ + Packages: []*v2_2.Package{ pkgWith, }, Files: unFiles, - OtherLicenses: []*spdx.OtherLicense2_2{ + OtherLicenses: []*v2_2.OtherLicense{ ol1, ol2, }, - Relationships: []*spdx.Relationship2_2{ + Relationships: []*v2_2.Relationship{ rln1, rln2, rln3, }, - Annotations: []*spdx.Annotation2_2{ + Annotations: []*v2_2.Annotation{ ann1, ann2, }, - Reviews: []*spdx.Review2_2{ + Reviews: []*v2_2.Review{ rev1, rev2, }, @@ -332,7 +333,7 @@ ReviewComment: I have reviewed this SPDX document and it is awesome } func TestSaver2_2DocumentReturnsErrorIfNilCreationInfo(t *testing.T) { - doc := &spdx.Document2_2{} + doc := &v2_2.Document{} var got bytes.Buffer err := RenderDocument2_2(doc, &got) diff --git a/tvsaver/saver2v2/save_file.go b/tvsaver/saver2v2/save_file.go index f1684efb..1c367a85 100644 --- a/tvsaver/saver2v2/save_file.go +++ b/tvsaver/saver2v2/save_file.go @@ -7,15 +7,16 @@ import ( "io" "sort" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) -func renderFile2_2(f *spdx.File2_2, w io.Writer) error { +func renderFile2_2(f *v2_2.File, w io.Writer) error { if f.FileName != "" { fmt.Fprintf(w, "FileName: %s\n", f.FileName) } if f.FileSPDXIdentifier != "" { - fmt.Fprintf(w, "SPDXID: %s\n", spdx.RenderElementID(f.FileSPDXIdentifier)) + fmt.Fprintf(w, "SPDXID: %s\n", common.RenderElementID(f.FileSPDXIdentifier)) } for _, s := range f.FileTypes { fmt.Fprintf(w, "FileType: %s\n", s) @@ -72,7 +73,7 @@ func renderFile2_2(f *spdx.File2_2, w io.Writer) error { } sort.Strings(snippetKeys) for _, sID := range snippetKeys { - s := f.Snippets[spdx.ElementID(sID)] + s := f.Snippets[common.ElementID(sID)] renderSnippet2_2(s, w) } diff --git a/tvsaver/saver2v2/save_file_test.go b/tvsaver/saver2v2/save_file_test.go index c49c978b..f8a8f324 100644 --- a/tvsaver/saver2v2/save_file_test.go +++ b/tvsaver/saver2v2/save_file_test.go @@ -6,22 +6,23 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== File section Saver tests ===== func TestSaver2_2FileSavesText(t *testing.T) { - f := &spdx.File2_2{ + f := &v2_2.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), + FileSPDXIdentifier: common.ElementID("File123"), FileTypes: []string{ "TEXT", "DOCUMENTATION", }, - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, - {Algorithm: spdx.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd"}, - {Algorithm: spdx.MD5, Value: "624c1abb3664f4b35547e7c73864ad24"}, + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + {Algorithm: common.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd"}, + {Algorithm: common.MD5, Value: "624c1abb3664f4b35547e7c73864ad24"}, }, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ @@ -30,20 +31,20 @@ func TestSaver2_2FileSavesText(t *testing.T) { }, LicenseComments: "this is a license comment(s)", FileCopyrightText: "Copyright (c) Jane Doe", - ArtifactOfProjects: []*spdx.ArtifactOfProject2_2{ - &spdx.ArtifactOfProject2_2{ + ArtifactOfProjects: []*v2_2.ArtifactOfProject{ + &v2_2.ArtifactOfProject{ Name: "project1", HomePage: "http://example.com/1/", URI: "http://example.com/1/uri.whatever", }, - &spdx.ArtifactOfProject2_2{ + &v2_2.ArtifactOfProject{ Name: "project2", }, - &spdx.ArtifactOfProject2_2{ + &v2_2.ArtifactOfProject{ Name: "project3", HomePage: "http://example.com/3/", }, - &spdx.ArtifactOfProject2_2{ + &v2_2.ArtifactOfProject{ Name: "project4", URI: "http://example.com/4/uri.whatever", }, @@ -113,32 +114,32 @@ FileDependency: g.txt } func TestSaver2_2FileSavesSnippetsAlso(t *testing.T) { - sn1 := &spdx.Snippet2_2{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet19"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File123").ElementRefID, - Ranges: []spdx.SnippetRange{{StartPointer: spdx.SnippetRangePointer{Offset: 17}, EndPointer: spdx.SnippetRangePointer{Offset: 209}}}, + sn1 := &v2_2.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet19"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File123").ElementRefID, + Ranges: []common.SnippetRange{{StartPointer: common.SnippetRangePointer{Offset: 17}, EndPointer: common.SnippetRangePointer{Offset: 209}}}, SnippetLicenseConcluded: "GPL-2.0-or-later", SnippetCopyrightText: "Copyright (c) John Doe 20x6", } - sn2 := &spdx.Snippet2_2{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet20"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File123").ElementRefID, - Ranges: []spdx.SnippetRange{{StartPointer: spdx.SnippetRangePointer{Offset: 268}, EndPointer: spdx.SnippetRangePointer{Offset: 309}}}, + sn2 := &v2_2.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet20"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File123").ElementRefID, + Ranges: []common.SnippetRange{{StartPointer: common.SnippetRangePointer{Offset: 268}, EndPointer: common.SnippetRangePointer{Offset: 309}}}, SnippetLicenseConcluded: "WTFPL", SnippetCopyrightText: "NOASSERTION", } - sns := map[spdx.ElementID]*spdx.Snippet2_2{ - spdx.ElementID("Snippet19"): sn1, - spdx.ElementID("Snippet20"): sn2, + sns := map[common.ElementID]*v2_2.Snippet{ + common.ElementID("Snippet19"): sn1, + common.ElementID("Snippet20"): sn2, } - f := &spdx.File2_2{ + f := &v2_2.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + FileSPDXIdentifier: common.ElementID("File123"), + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, }, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ @@ -185,11 +186,11 @@ SnippetCopyrightText: NOASSERTION } func TestSaver2_2FileOmitsOptionalFieldsIfEmpty(t *testing.T) { - f := &spdx.File2_2{ + f := &v2_2.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + FileSPDXIdentifier: common.ElementID("File123"), + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, }, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ @@ -223,11 +224,11 @@ FileCopyrightText: Copyright (c) Jane Doe } func TestSaver2_2FileWrapsCopyrightMultiLine(t *testing.T) { - f := &spdx.File2_2{ + f := &v2_2.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + FileSPDXIdentifier: common.ElementID("File123"), + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, }, LicenseConcluded: "Apache-2.0", LicenseInfoInFiles: []string{ @@ -263,11 +264,11 @@ Copyright (c) John Doe } func TestSaver2_2FileWrapsCommentsAndNoticesMultiLine(t *testing.T) { - f := &spdx.File2_2{ + f := &v2_2.File{ FileName: "/tmp/whatever.txt", - FileSPDXIdentifier: spdx.ElementID("File123"), - Checksums: []spdx.Checksum{ - {Algorithm: spdx.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, + FileSPDXIdentifier: common.ElementID("File123"), + Checksums: []common.Checksum{ + {Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c"}, }, LicenseComments: `this is a multi-line license comment`, diff --git a/tvsaver/saver2v2/save_other_license.go b/tvsaver/saver2v2/save_other_license.go index eaac9ac2..9fad2097 100644 --- a/tvsaver/saver2v2/save_other_license.go +++ b/tvsaver/saver2v2/save_other_license.go @@ -6,10 +6,10 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) -func renderOtherLicense2_2(ol *spdx.OtherLicense2_2, w io.Writer) error { +func renderOtherLicense2_2(ol *v2_2.OtherLicense, w io.Writer) error { if ol.LicenseIdentifier != "" { fmt.Fprintf(w, "LicenseID: %s\n", ol.LicenseIdentifier) } diff --git a/tvsaver/saver2v2/save_other_license_test.go b/tvsaver/saver2v2/save_other_license_test.go index 982e1094..6b715220 100644 --- a/tvsaver/saver2v2/save_other_license_test.go +++ b/tvsaver/saver2v2/save_other_license_test.go @@ -6,12 +6,12 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Other License section Saver tests ===== func TestSaver2_2OtherLicenseSavesText(t *testing.T) { - ol := &spdx.OtherLicense2_2{ + ol := &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-1", ExtractedText: `License 1 text blah blah blah @@ -51,7 +51,7 @@ LicenseComment: this is a license comment } func TestSaver2_2OtherLicenseOmitsOptionalFieldsIfEmpty(t *testing.T) { - ol := &spdx.OtherLicense2_2{ + ol := &v2_2.OtherLicense{ LicenseIdentifier: "LicenseRef-1", ExtractedText: `License 1 text blah blah blah diff --git a/tvsaver/saver2v2/save_package.go b/tvsaver/saver2v2/save_package.go index 6d21a6d2..387fe2ae 100644 --- a/tvsaver/saver2v2/save_package.go +++ b/tvsaver/saver2v2/save_package.go @@ -8,15 +8,16 @@ import ( "sort" "strings" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) -func renderPackage2_2(pkg *spdx.Package2_2, w io.Writer) error { +func renderPackage2_2(pkg *v2_2.Package, w io.Writer) error { if pkg.PackageName != "" { fmt.Fprintf(w, "PackageName: %s\n", pkg.PackageName) } if pkg.PackageSPDXIdentifier != "" { - fmt.Fprintf(w, "SPDXID: %s\n", spdx.RenderElementID(pkg.PackageSPDXIdentifier)) + fmt.Fprintf(w, "SPDXID: %s\n", common.RenderElementID(pkg.PackageSPDXIdentifier)) } if pkg.PackageVersion != "" { fmt.Fprintf(w, "PackageVersion: %s\n", pkg.PackageVersion) diff --git a/tvsaver/saver2v2/save_package_test.go b/tvsaver/saver2v2/save_package_test.go index f9960f0a..45f9851e 100644 --- a/tvsaver/saver2v2/save_package_test.go +++ b/tvsaver/saver2v2/save_package_test.go @@ -6,7 +6,8 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Package section Saver tests ===== @@ -17,7 +18,7 @@ func TestSaver2_2PackageSavesTextCombo1(t *testing.T) { // PackageVerificationCodeExcludedFile has string // NOTE, this is an entirely made up CPE and the format is likely invalid - per1 := &spdx.PackageExternalReference2_2{ + per1 := &v2_2.PackageExternalReference{ Category: "SECURITY", RefType: "cpe22Type", Locator: "cpe:/a:john_doe_inc:p1:0.1.0", @@ -25,7 +26,7 @@ func TestSaver2_2PackageSavesTextCombo1(t *testing.T) { } // NOTE, this is an entirely made up NPM - per2 := &spdx.PackageExternalReference2_2{ + per2 := &v2_2.PackageExternalReference{ Category: "PACKAGE-MANAGER", RefType: "npm", Locator: "p1@0.1.0", @@ -34,45 +35,45 @@ multi-line external ref comment`, } // NOTE, this is an entirely made up SWH persistent ID - per3 := &spdx.PackageExternalReference2_2{ + per3 := &v2_2.PackageExternalReference{ Category: "PERSISTENT-ID", RefType: "swh", Locator: "swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2", // no ExternalRefComment for this one } - per4 := &spdx.PackageExternalReference2_2{ + per4 := &v2_2.PackageExternalReference{ Category: "OTHER", RefType: "anything", Locator: "anything-without-spaces-can-go-here", // no ExternalRefComment for this one } - pkg := &spdx.Package2_2{ + pkg := &v2_2.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageVersion: "0.1.0", PackageFileName: "p1-0.1.0-master.tar.gz", - PackageSupplier: &spdx.Supplier{SupplierType: "Organization", Supplier: "John Doe, Inc."}, - PackageOriginator: &spdx.Originator{Originator: "John Doe", OriginatorType: "Person"}, + PackageSupplier: &common.Supplier{SupplierType: "Organization", Supplier: "John Doe, Inc."}, + PackageOriginator: &common.Originator{Originator: "John Doe", OriginatorType: "Person"}, PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: true, - PackageVerificationCode: spdx.PackageVerificationCode{ + PackageVerificationCode: common.PackageVerificationCode{ Value: "0123456789abcdef0123456789abcdef01234567", ExcludedFiles: []string{"p1-0.1.0.spdx"}, }, - PackageChecksums: []spdx.Checksum{ + PackageChecksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c", }, { - Algorithm: spdx.SHA256, + Algorithm: common.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd", }, { - Algorithm: spdx.MD5, + Algorithm: common.MD5, Value: "624c1abb3664f4b35547e7c73864ad24", }, }, @@ -91,7 +92,7 @@ multi-line external ref comment`, PackageDescription: "this is a description comment", PackageComment: "this is a comment comment", PackageAttributionTexts: []string{"Include this notice in all advertising materials"}, - PackageExternalReferences: []*spdx.PackageExternalReference2_2{ + PackageExternalReferences: []*v2_2.PackageExternalReference{ per1, per2, per3, @@ -155,28 +156,28 @@ func TestSaver2_2PackageSavesTextCombo2(t *testing.T) { // FilesAnalyzed true, IsFilesAnalyzedTagPresent false // PackageVerificationCodeExcludedFile is empty - pkg := &spdx.Package2_2{ + pkg := &v2_2.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageVersion: "0.1.0", PackageFileName: "p1-0.1.0-master.tar.gz", - PackageSupplier: &spdx.Supplier{Supplier: "NOASSERTION"}, - PackageOriginator: &spdx.Originator{OriginatorType: "Organization", Originator: "John Doe, Inc."}, + PackageSupplier: &common.Supplier{Supplier: "NOASSERTION"}, + PackageOriginator: &common.Originator{OriginatorType: "Organization", Originator: "John Doe, Inc."}, PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: true, IsFilesAnalyzedTagPresent: false, - PackageVerificationCode: spdx.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, - PackageChecksums: []spdx.Checksum{ + PackageVerificationCode: common.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, + PackageChecksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c", }, { - Algorithm: spdx.SHA256, + Algorithm: common.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd", }, { - Algorithm: spdx.MD5, + Algorithm: common.MD5, Value: "624c1abb3664f4b35547e7c73864ad24", }, }, @@ -246,30 +247,30 @@ func TestSaver2_2PackageSavesTextCombo3(t *testing.T) { // PackageVerificationCodeExcludedFile is empty // three PackageAttributionTexts, one with multi-line text - pkg := &spdx.Package2_2{ + pkg := &v2_2.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageVersion: "0.1.0", PackageFileName: "p1-0.1.0-master.tar.gz", - PackageSupplier: &spdx.Supplier{Supplier: "John Doe", SupplierType: "Person"}, - PackageOriginator: &spdx.Originator{Originator: "NOASSERTION"}, + PackageSupplier: &common.Supplier{Supplier: "John Doe", SupplierType: "Person"}, + PackageOriginator: &common.Originator{Originator: "NOASSERTION"}, PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: false, IsFilesAnalyzedTagPresent: true, // NOTE that verification code MUST be omitted from output // since FilesAnalyzed is false - PackageVerificationCode: spdx.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, - PackageChecksums: []spdx.Checksum{ + PackageVerificationCode: common.PackageVerificationCode{Value: "0123456789abcdef0123456789abcdef01234567"}, + PackageChecksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c", }, { - Algorithm: spdx.SHA256, + Algorithm: common.SHA256, Value: "11b6d3ee554eedf79299905a98f9b9a04e498210b59f15094c916c91d150efcd", }, { - Algorithm: spdx.MD5, + Algorithm: common.MD5, Value: "624c1abb3664f4b35547e7c73864ad24", }, }, @@ -340,9 +341,9 @@ which goes across two lines } func TestSaver2_2PackageSaveOmitsOptionalFieldsIfEmpty(t *testing.T) { - pkg := &spdx.Package2_2{ + pkg := &v2_2.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: false, IsFilesAnalyzedTagPresent: true, @@ -386,12 +387,12 @@ PackageCopyrightText: Copyright (c) John Doe, Inc. } func TestSaver2_2PackageSavesFilesIfPresent(t *testing.T) { - f1 := &spdx.File2_2{ + f1 := &v2_2.File{ FileName: "/tmp/whatever1.txt", - FileSPDXIdentifier: spdx.ElementID("File1231"), - Checksums: []spdx.Checksum{ + FileSPDXIdentifier: common.ElementID("File1231"), + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983c", }, }, @@ -400,12 +401,12 @@ func TestSaver2_2PackageSavesFilesIfPresent(t *testing.T) { FileCopyrightText: "Copyright (c) Jane Doe", } - f2 := &spdx.File2_2{ + f2 := &v2_2.File{ FileName: "/tmp/whatever2.txt", - FileSPDXIdentifier: spdx.ElementID("File1232"), - Checksums: []spdx.Checksum{ + FileSPDXIdentifier: common.ElementID("File1232"), + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "85ed0817af83a24ad8da68c2b5094de69833983d", }, }, @@ -414,9 +415,9 @@ func TestSaver2_2PackageSavesFilesIfPresent(t *testing.T) { FileCopyrightText: "Copyright (c) John Doe", } - pkg := &spdx.Package2_2{ + pkg := &v2_2.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: false, IsFilesAnalyzedTagPresent: true, @@ -432,7 +433,7 @@ func TestSaver2_2PackageSavesFilesIfPresent(t *testing.T) { }, PackageLicenseDeclared: "Apache-2.0 OR GPL-2.0-or-later", PackageCopyrightText: "Copyright (c) John Doe, Inc.", - Files: []*spdx.File2_2{ + Files: []*v2_2.File{ f1, f2, }, @@ -478,9 +479,9 @@ FileCopyrightText: Copyright (c) John Doe } func TestSaver2_2PackageWrapsMultiLine(t *testing.T) { - pkg := &spdx.Package2_2{ + pkg := &v2_2.Package{ PackageName: "p1", - PackageSPDXIdentifier: spdx.ElementID("p1"), + PackageSPDXIdentifier: common.ElementID("p1"), PackageDownloadLocation: "http://example.com/p1/p1-0.1.0-master.tar.gz", FilesAnalyzed: false, IsFilesAnalyzedTagPresent: true, diff --git a/tvsaver/saver2v2/save_relationship.go b/tvsaver/saver2v2/save_relationship.go index 4bd12ddb..a9621200 100644 --- a/tvsaver/saver2v2/save_relationship.go +++ b/tvsaver/saver2v2/save_relationship.go @@ -6,12 +6,13 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) -func renderRelationship2_2(rln *spdx.Relationship2_2, w io.Writer) error { - rlnAStr := spdx.RenderDocElementID(rln.RefA) - rlnBStr := spdx.RenderDocElementID(rln.RefB) +func renderRelationship2_2(rln *v2_2.Relationship, w io.Writer) error { + rlnAStr := common.RenderDocElementID(rln.RefA) + rlnBStr := common.RenderDocElementID(rln.RefB) if rlnAStr != "SPDXRef-" && rlnBStr != "SPDXRef-" && rln.Relationship != "" { fmt.Fprintf(w, "Relationship: %s %s %s\n", rlnAStr, rln.Relationship, rlnBStr) } diff --git a/tvsaver/saver2v2/save_relationship_test.go b/tvsaver/saver2v2/save_relationship_test.go index ebb3e378..927164c3 100644 --- a/tvsaver/saver2v2/save_relationship_test.go +++ b/tvsaver/saver2v2/save_relationship_test.go @@ -6,14 +6,15 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Relationship section Saver tests ===== func TestSaver2_2RelationshipSavesText(t *testing.T) { - rln := &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "2"), + rln := &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "2"), Relationship: "DESCRIBES", RelationshipComment: "this is a comment", } @@ -39,9 +40,9 @@ RelationshipComment: this is a comment } func TestSaver2_2RelationshipOmitsOptionalFieldsIfEmpty(t *testing.T) { - rln := &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "2"), + rln := &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "2"), Relationship: "DESCRIBES", } @@ -64,9 +65,9 @@ func TestSaver2_2RelationshipOmitsOptionalFieldsIfEmpty(t *testing.T) { } func TestSaver2_2RelationshipCanHaveNONEOnRight(t *testing.T) { - rln := &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "PackageA"), - RefB: spdx.MakeDocElementSpecial("NONE"), + rln := &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "PackageA"), + RefB: common.MakeDocElementSpecial("NONE"), Relationship: "DEPENDS_ON", } @@ -89,9 +90,9 @@ func TestSaver2_2RelationshipCanHaveNONEOnRight(t *testing.T) { } func TestSaver2_2RelationshipCanHaveNOASSERTIONOnRight(t *testing.T) { - rln := &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "PackageA"), - RefB: spdx.MakeDocElementSpecial("NOASSERTION"), + rln := &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "PackageA"), + RefB: common.MakeDocElementSpecial("NOASSERTION"), Relationship: "DEPENDS_ON", } @@ -114,9 +115,9 @@ func TestSaver2_2RelationshipCanHaveNOASSERTIONOnRight(t *testing.T) { } func TestSaver2_2RelationshipWrapsCommentMultiLine(t *testing.T) { - rln := &spdx.Relationship2_2{ - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "2"), + rln := &v2_2.Relationship{ + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "2"), Relationship: "DESCRIBES", RelationshipComment: `this is a multi-line comment`, diff --git a/tvsaver/saver2v2/save_review.go b/tvsaver/saver2v2/save_review.go index 48004e4d..8f1add6f 100644 --- a/tvsaver/saver2v2/save_review.go +++ b/tvsaver/saver2v2/save_review.go @@ -6,10 +6,10 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) -func renderReview2_2(rev *spdx.Review2_2, w io.Writer) error { +func renderReview2_2(rev *v2_2.Review, w io.Writer) error { if rev.Reviewer != "" && rev.ReviewerType != "" { fmt.Fprintf(w, "Reviewer: %s: %s\n", rev.ReviewerType, rev.Reviewer) } diff --git a/tvsaver/saver2v2/save_review_test.go b/tvsaver/saver2v2/save_review_test.go index 25fe469c..961daa12 100644 --- a/tvsaver/saver2v2/save_review_test.go +++ b/tvsaver/saver2v2/save_review_test.go @@ -6,12 +6,12 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Review section Saver tests ===== func TestSaver2_2ReviewSavesText(t *testing.T) { - rev := &spdx.Review2_2{ + rev := &v2_2.Review{ Reviewer: "John Doe", ReviewerType: "Person", ReviewDate: "2018-10-14T10:28:00Z", @@ -40,7 +40,7 @@ ReviewComment: this is a review comment } func TestSaver2_2ReviewOmitsOptionalFieldsIfEmpty(t *testing.T) { - rev := &spdx.Review2_2{ + rev := &v2_2.Review{ Reviewer: "John Doe", ReviewerType: "Person", ReviewDate: "2018-10-14T10:28:00Z", @@ -67,7 +67,7 @@ ReviewDate: 2018-10-14T10:28:00Z } func TestSaver2_2ReviewWrapsMultiLine(t *testing.T) { - rev := &spdx.Review2_2{ + rev := &v2_2.Review{ Reviewer: "John Doe", ReviewerType: "Person", ReviewDate: "2018-10-14T10:28:00Z", diff --git a/tvsaver/saver2v2/save_snippet.go b/tvsaver/saver2v2/save_snippet.go index 4f740982..d1254db7 100644 --- a/tvsaver/saver2v2/save_snippet.go +++ b/tvsaver/saver2v2/save_snippet.go @@ -6,14 +6,15 @@ import ( "fmt" "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) -func renderSnippet2_2(sn *spdx.Snippet2_2, w io.Writer) error { +func renderSnippet2_2(sn *v2_2.Snippet, w io.Writer) error { if sn.SnippetSPDXIdentifier != "" { - fmt.Fprintf(w, "SnippetSPDXID: %s\n", spdx.RenderElementID(sn.SnippetSPDXIdentifier)) + fmt.Fprintf(w, "SnippetSPDXID: %s\n", common.RenderElementID(sn.SnippetSPDXIdentifier)) } - snFromFileIDStr := spdx.RenderElementID(sn.SnippetFromFileSPDXIdentifier) + snFromFileIDStr := common.RenderElementID(sn.SnippetFromFileSPDXIdentifier) if snFromFileIDStr != "" { fmt.Fprintf(w, "SnippetFromFileSPDXID: %s\n", snFromFileIDStr) } diff --git a/tvsaver/saver2v2/save_snippet_test.go b/tvsaver/saver2v2/save_snippet_test.go index da91b991..72daf159 100644 --- a/tvsaver/saver2v2/save_snippet_test.go +++ b/tvsaver/saver2v2/save_snippet_test.go @@ -6,22 +6,23 @@ import ( "bytes" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== Snippet section Saver tests ===== func TestSaver2_2SnippetSavesText(t *testing.T) { - sn := &spdx.Snippet2_2{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet17"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292").ElementRefID, - Ranges: []spdx.SnippetRange{ + sn := &v2_2.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet17"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File292").ElementRefID, + Ranges: []common.SnippetRange{ { - StartPointer: spdx.SnippetRangePointer{LineNumber: 3}, - EndPointer: spdx.SnippetRangePointer{LineNumber: 8}, + StartPointer: common.SnippetRangePointer{LineNumber: 3}, + EndPointer: common.SnippetRangePointer{LineNumber: 8}, }, { - StartPointer: spdx.SnippetRangePointer{Offset: 17}, - EndPointer: spdx.SnippetRangePointer{Offset: 209}, + StartPointer: common.SnippetRangePointer{Offset: 17}, + EndPointer: common.SnippetRangePointer{Offset: 209}, }, }, SnippetLicenseConcluded: "GPL-2.0-or-later", @@ -67,13 +68,13 @@ SnippetAttributionText: some attributions } func TestSaver2_2SnippetOmitsOptionalFieldsIfEmpty(t *testing.T) { - sn := &spdx.Snippet2_2{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet17"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292").ElementRefID, - Ranges: []spdx.SnippetRange{ + sn := &v2_2.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet17"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File292").ElementRefID, + Ranges: []common.SnippetRange{ { - StartPointer: spdx.SnippetRangePointer{Offset: 17}, - EndPointer: spdx.SnippetRangePointer{Offset: 209}, + StartPointer: common.SnippetRangePointer{Offset: 17}, + EndPointer: common.SnippetRangePointer{Offset: 209}, }, }, SnippetLicenseConcluded: "GPL-2.0-or-later", @@ -104,13 +105,13 @@ SnippetCopyrightText: Copyright (c) John Doe 20x6 } func TestSaver2_2SnippetWrapsCopyrightMultiline(t *testing.T) { - sn := &spdx.Snippet2_2{ - SnippetSPDXIdentifier: spdx.ElementID("Snippet17"), - SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292").ElementRefID, - Ranges: []spdx.SnippetRange{ + sn := &v2_2.Snippet{ + SnippetSPDXIdentifier: common.ElementID("Snippet17"), + SnippetFromFileSPDXIdentifier: common.MakeDocElementID("", "File292").ElementRefID, + Ranges: []common.SnippetRange{ { - StartPointer: spdx.SnippetRangePointer{Offset: 17}, - EndPointer: spdx.SnippetRangePointer{Offset: 209}, + StartPointer: common.SnippetRangePointer{Offset: 17}, + EndPointer: common.SnippetRangePointer{Offset: 209}, }, }, SnippetLicenseConcluded: "GPL-2.0-or-later", diff --git a/tvsaver/tvsaver.go b/tvsaver/tvsaver.go index 002b0e94..09d16dc4 100644 --- a/tvsaver/tvsaver.go +++ b/tvsaver/tvsaver.go @@ -6,7 +6,8 @@ package tvsaver import ( "io" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" "github.com/spdx/tools-golang/tvsaver/saver2v1" "github.com/spdx/tools-golang/tvsaver/saver2v2" ) @@ -14,13 +15,13 @@ import ( // Save2_1 takes an io.Writer and an SPDX Document (version 2.1), // and writes it to the writer in tag-value format. It returns error // if any error is encountered. -func Save2_1(doc *spdx.Document2_1, w io.Writer) error { +func Save2_1(doc *v2_1.Document, w io.Writer) error { return saver2v1.RenderDocument2_1(doc, w) } // Save2_2 takes an io.Writer and an SPDX Document (version 2.2), // and writes it to the writer in tag-value format. It returns error // if any error is encountered. -func Save2_2(doc *spdx.Document2_2, w io.Writer) error { +func Save2_2(doc *v2_2.Document, w io.Writer) error { return saver2v2.RenderDocument2_2(doc, w) } diff --git a/utils/verification.go b/utils/verification.go index 94e8b7ef..bd6c8758 100644 --- a/utils/verification.go +++ b/utils/verification.go @@ -9,23 +9,25 @@ import ( "sort" "strings" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" ) // GetVerificationCode2_1 takes a slice of files and an optional filename // for an "excludes" file, and returns a Package Verification Code calculated // according to SPDX spec version 2.1, section 3.9.4. -func GetVerificationCode2_1(files []*spdx.File2_1, excludeFile string) (spdx.PackageVerificationCode, error) { +func GetVerificationCode2_1(files []*v2_1.File, excludeFile string) (common.PackageVerificationCode, error) { // create slice of strings - unsorted SHA1s for all files shas := []string{} for i, f := range files { if f == nil { - return spdx.PackageVerificationCode{}, fmt.Errorf("got nil file for identifier %v", i) + return common.PackageVerificationCode{}, fmt.Errorf("got nil file for identifier %v", i) } if f.FileName != excludeFile { // find the SHA1 hash, if present for _, checksum := range f.Checksums { - if checksum.Algorithm == spdx.SHA1 { + if checksum.Algorithm == common.SHA1 { shas = append(shas, checksum.Value) } } @@ -43,7 +45,7 @@ func GetVerificationCode2_1(files []*spdx.File2_1, excludeFile string) (spdx.Pac hsha1.Write([]byte(shasConcat)) bs := hsha1.Sum(nil) - code := spdx.PackageVerificationCode{ + code := common.PackageVerificationCode{ Value: fmt.Sprintf("%x", bs), ExcludedFiles: []string{excludeFile}, } @@ -54,17 +56,17 @@ func GetVerificationCode2_1(files []*spdx.File2_1, excludeFile string) (spdx.Pac // GetVerificationCode2_2 takes a slice of files and an optional filename // for an "excludes" file, and returns a Package Verification Code calculated // according to SPDX spec version 2.2, section 3.9.4. -func GetVerificationCode2_2(files []*spdx.File2_2, excludeFile string) (spdx.PackageVerificationCode, error) { +func GetVerificationCode2_2(files []*v2_2.File, excludeFile string) (common.PackageVerificationCode, error) { // create slice of strings - unsorted SHA1s for all files shas := []string{} for i, f := range files { if f == nil { - return spdx.PackageVerificationCode{}, fmt.Errorf("got nil file for identifier %v", i) + return common.PackageVerificationCode{}, fmt.Errorf("got nil file for identifier %v", i) } if f.FileName != excludeFile { // find the SHA1 hash, if present for _, checksum := range f.Checksums { - if checksum.Algorithm == spdx.SHA1 { + if checksum.Algorithm == common.SHA1 { shas = append(shas, checksum.Value) } } @@ -82,7 +84,7 @@ func GetVerificationCode2_2(files []*spdx.File2_2, excludeFile string) (spdx.Pac hsha1.Write([]byte(shasConcat)) bs := hsha1.Sum(nil) - code := spdx.PackageVerificationCode{ + code := common.PackageVerificationCode{ Value: fmt.Sprintf("%x", bs), ExcludedFiles: []string{excludeFile}, } diff --git a/utils/verification_test.go b/utils/verification_test.go index d31614af..3fa4ead3 100644 --- a/utils/verification_test.go +++ b/utils/verification_test.go @@ -5,41 +5,43 @@ package utils import ( "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_1" + "github.com/spdx/tools-golang/spdx/v2_2" ) // ===== 2.1 Verification code functionality tests ===== func TestPackage2_1CanGetVerificationCode(t *testing.T) { - files := []*spdx.File2_1{ + files := []*v2_1.File{ { FileName: "file2.txt", FileSPDXIdentifier: "File0", - Checksums: []spdx.Checksum{{Value: "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd", Algorithm: spdx.SHA1}}, + Checksums: []common.Checksum{{Value: "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd", Algorithm: common.SHA1}}, }, { FileName: "file1.txt", FileSPDXIdentifier: "File1", - Checksums: []spdx.Checksum{{Value: "3333333333bbbbbbbbbbccccccccccdddddddddd", Algorithm: spdx.SHA1}}, + Checksums: []common.Checksum{{Value: "3333333333bbbbbbbbbbccccccccccdddddddddd", Algorithm: common.SHA1}}, }, { FileName: "file3.txt", FileSPDXIdentifier: "File2", - Checksums: []spdx.Checksum{{Value: "8888888888bbbbbbbbbbccccccccccdddddddddd", Algorithm: spdx.SHA1}}, + Checksums: []common.Checksum{{Value: "8888888888bbbbbbbbbbccccccccccdddddddddd", Algorithm: common.SHA1}}, }, { FileName: "file5.txt", FileSPDXIdentifier: "File3", - Checksums: []spdx.Checksum{{Value: "2222222222bbbbbbbbbbccccccccccdddddddddd", Algorithm: spdx.SHA1}}, + Checksums: []common.Checksum{{Value: "2222222222bbbbbbbbbbccccccccccdddddddddd", Algorithm: common.SHA1}}, }, { FileName: "file4.txt", FileSPDXIdentifier: "File4", - Checksums: []spdx.Checksum{{Value: "bbbbbbbbbbccccccccccddddddddddaaaaaaaaaa", Algorithm: spdx.SHA1}}, + Checksums: []common.Checksum{{Value: "bbbbbbbbbbccccccccccddddddddddaaaaaaaaaa", Algorithm: common.SHA1}}, }, } - wantCode := spdx.PackageVerificationCode{Value: "ac924b375119c81c1f08c3e2722044bfbbdcd3dc"} + wantCode := common.PackageVerificationCode{Value: "ac924b375119c81c1f08c3e2722044bfbbdcd3dc"} gotCode, err := GetVerificationCode2_1(files, "") if err != nil { @@ -52,35 +54,35 @@ func TestPackage2_1CanGetVerificationCode(t *testing.T) { } func TestPackage2_1CanGetVerificationCodeIgnoringExcludesFile(t *testing.T) { - files := []*spdx.File2_1{ + files := []*v2_1.File{ { FileName: "file1.txt", FileSPDXIdentifier: "File0", - Checksums: []spdx.Checksum{{Value: "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd", Algorithm: spdx.SHA1}}, + Checksums: []common.Checksum{{Value: "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd", Algorithm: common.SHA1}}, }, { FileName: "file2.txt", FileSPDXIdentifier: "File1", - Checksums: []spdx.Checksum{{Value: "3333333333bbbbbbbbbbccccccccccdddddddddd", Algorithm: spdx.SHA1}}, + Checksums: []common.Checksum{{Value: "3333333333bbbbbbbbbbccccccccccdddddddddd", Algorithm: common.SHA1}}, }, { FileName: "thisfile.spdx", FileSPDXIdentifier: "File2", - Checksums: []spdx.Checksum{{Value: "bbbbbbbbbbccccccccccddddddddddaaaaaaaaaa", Algorithm: spdx.SHA1}}, + Checksums: []common.Checksum{{Value: "bbbbbbbbbbccccccccccddddddddddaaaaaaaaaa", Algorithm: common.SHA1}}, }, { FileName: "file3.txt", FileSPDXIdentifier: "File3", - Checksums: []spdx.Checksum{{Value: "8888888888bbbbbbbbbbccccccccccdddddddddd", Algorithm: spdx.SHA1}}, + Checksums: []common.Checksum{{Value: "8888888888bbbbbbbbbbccccccccccdddddddddd", Algorithm: common.SHA1}}, }, { FileName: "file4.txt", FileSPDXIdentifier: "File4", - Checksums: []spdx.Checksum{{Value: "2222222222bbbbbbbbbbccccccccccdddddddddd", Algorithm: spdx.SHA1}}, + Checksums: []common.Checksum{{Value: "2222222222bbbbbbbbbbccccccccccdddddddddd", Algorithm: common.SHA1}}, }, } - wantCode := spdx.PackageVerificationCode{Value: "17fab1bd18fe5c13b5d3983f1c17e5f88b8ff266"} + wantCode := common.PackageVerificationCode{Value: "17fab1bd18fe5c13b5d3983f1c17e5f88b8ff266"} gotCode, err := GetVerificationCode2_1(files, "thisfile.spdx") if err != nil { @@ -92,17 +94,17 @@ func TestPackage2_1CanGetVerificationCodeIgnoringExcludesFile(t *testing.T) { } func TestPackage2_1GetVerificationCodeFailsIfNilFileInSlice(t *testing.T) { - files := []*spdx.File2_1{ + files := []*v2_1.File{ { FileName: "file2.txt", FileSPDXIdentifier: "File0", - Checksums: []spdx.Checksum{{Value: "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd", Algorithm: spdx.SHA1}}, + Checksums: []common.Checksum{{Value: "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd", Algorithm: common.SHA1}}, }, nil, { FileName: "file3.txt", FileSPDXIdentifier: "File2", - Checksums: []spdx.Checksum{{Value: "8888888888bbbbbbbbbbccccccccccdddddddddd", Algorithm: spdx.SHA1}}, + Checksums: []common.Checksum{{Value: "8888888888bbbbbbbbbbccccccccccdddddddddd", Algorithm: common.SHA1}}, }, } @@ -115,13 +117,13 @@ func TestPackage2_1GetVerificationCodeFailsIfNilFileInSlice(t *testing.T) { // ===== 2.2 Verification code functionality tests ===== func TestPackage2_2CanGetVerificationCode(t *testing.T) { - files := []*spdx.File2_2{ + files := []*v2_2.File{ { FileName: "file2.txt", FileSPDXIdentifier: "File0", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd", }, }, @@ -129,9 +131,9 @@ func TestPackage2_2CanGetVerificationCode(t *testing.T) { { FileName: "file1.txt", FileSPDXIdentifier: "File1", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "3333333333bbbbbbbbbbccccccccccdddddddddd", }, }, @@ -139,9 +141,9 @@ func TestPackage2_2CanGetVerificationCode(t *testing.T) { { FileName: "file3.txt", FileSPDXIdentifier: "File2", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "8888888888bbbbbbbbbbccccccccccdddddddddd", }, }, @@ -149,9 +151,9 @@ func TestPackage2_2CanGetVerificationCode(t *testing.T) { { FileName: "file5.txt", FileSPDXIdentifier: "File3", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "2222222222bbbbbbbbbbccccccccccdddddddddd", }, }, @@ -159,16 +161,16 @@ func TestPackage2_2CanGetVerificationCode(t *testing.T) { { FileName: "file4.txt", FileSPDXIdentifier: "File4", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "bbbbbbbbbbccccccccccddddddddddaaaaaaaaaa", }, }, }, } - wantCode := spdx.PackageVerificationCode{Value: "ac924b375119c81c1f08c3e2722044bfbbdcd3dc"} + wantCode := common.PackageVerificationCode{Value: "ac924b375119c81c1f08c3e2722044bfbbdcd3dc"} gotCode, err := GetVerificationCode2_2(files, "") if err != nil { @@ -181,13 +183,13 @@ func TestPackage2_2CanGetVerificationCode(t *testing.T) { } func TestPackage2_2CanGetVerificationCodeIgnoringExcludesFile(t *testing.T) { - files := []*spdx.File2_2{ + files := []*v2_2.File{ { FileName: "file1.txt", FileSPDXIdentifier: "File0", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd", }, }, @@ -195,9 +197,9 @@ func TestPackage2_2CanGetVerificationCodeIgnoringExcludesFile(t *testing.T) { { FileName: "file2.txt", FileSPDXIdentifier: "File1", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "3333333333bbbbbbbbbbccccccccccdddddddddd", }, }, @@ -205,9 +207,9 @@ func TestPackage2_2CanGetVerificationCodeIgnoringExcludesFile(t *testing.T) { { FileName: "thisfile.spdx", FileSPDXIdentifier: "File2", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "bbbbbbbbbbccccccccccddddddddddaaaaaaaaaa", }, }, @@ -215,9 +217,9 @@ func TestPackage2_2CanGetVerificationCodeIgnoringExcludesFile(t *testing.T) { { FileName: "file3.txt", FileSPDXIdentifier: "File3", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "8888888888bbbbbbbbbbccccccccccdddddddddd", }, }, @@ -225,16 +227,16 @@ func TestPackage2_2CanGetVerificationCodeIgnoringExcludesFile(t *testing.T) { { FileName: "file4.txt", FileSPDXIdentifier: "File4", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "2222222222bbbbbbbbbbccccccccccdddddddddd", }, }, }, } - wantCode := spdx.PackageVerificationCode{Value: "17fab1bd18fe5c13b5d3983f1c17e5f88b8ff266"} + wantCode := common.PackageVerificationCode{Value: "17fab1bd18fe5c13b5d3983f1c17e5f88b8ff266"} gotCode, err := GetVerificationCode2_2(files, "thisfile.spdx") if err != nil { @@ -246,13 +248,13 @@ func TestPackage2_2CanGetVerificationCodeIgnoringExcludesFile(t *testing.T) { } func TestPackage2_2GetVerificationCodeFailsIfNilFileInSlice(t *testing.T) { - files := []*spdx.File2_2{ + files := []*v2_2.File{ { FileName: "file2.txt", FileSPDXIdentifier: "File0", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd", }, }, @@ -261,9 +263,9 @@ func TestPackage2_2GetVerificationCodeFailsIfNilFileInSlice(t *testing.T) { { FileName: "file3.txt", FileSPDXIdentifier: "File2", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { - Algorithm: spdx.SHA1, + Algorithm: common.SHA1, Value: "8888888888bbbbbbbbbbccccccccccdddddddddd", }, }, diff --git a/yaml/parser.go b/yaml/parser.go index ca852ddf..1a8f0f6d 100644 --- a/yaml/parser.go +++ b/yaml/parser.go @@ -5,13 +5,13 @@ package spdx_yaml import ( "bytes" "io" - "sigs.k8s.io/yaml" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" + "sigs.k8s.io/yaml" ) // Load2_2 takes in an io.Reader and returns an SPDX document. -func Load2_2(content io.Reader) (*spdx.Document2_2, error) { +func Load2_2(content io.Reader) (*v2_2.Document, error) { // convert io.Reader to a slice of bytes and call the parser buf := new(bytes.Buffer) _, err := buf.ReadFrom(content) @@ -19,7 +19,7 @@ func Load2_2(content io.Reader) (*spdx.Document2_2, error) { return nil, err } - var doc spdx.Document2_2 + var doc v2_2.Document err = yaml.Unmarshal(buf.Bytes(), &doc) if err != nil { return nil, err diff --git a/yaml/writer.go b/yaml/writer.go index edd47936..cbc65081 100644 --- a/yaml/writer.go +++ b/yaml/writer.go @@ -4,13 +4,13 @@ package spdx_yaml import ( "io" - "sigs.k8s.io/yaml" - "github.com/spdx/tools-golang/spdx" + "github.com/spdx/tools-golang/spdx/v2_2" + "sigs.k8s.io/yaml" ) // Save2_2 takes an SPDX Document (version 2.2) and an io.Writer, and writes the document to the writer in YAML format. -func Save2_2(doc *spdx.Document2_2, w io.Writer) error { +func Save2_2(doc *v2_2.Document, w io.Writer) error { buf, err := yaml.Marshal(doc) if err != nil { return err diff --git a/yaml/yaml_test.go b/yaml/yaml_test.go index 49f8ebfe..c38b0e1f 100644 --- a/yaml/yaml_test.go +++ b/yaml/yaml_test.go @@ -5,11 +5,13 @@ package spdx_yaml import ( "bytes" "fmt" - "github.com/google/go-cmp/cmp" "os" "testing" - "github.com/spdx/tools-golang/spdx" + "github.com/google/go-cmp/cmp" + + "github.com/spdx/tools-golang/spdx/common" + "github.com/spdx/tools-golang/spdx/v2_2" ) func TestLoad2_2(t *testing.T) { @@ -58,15 +60,15 @@ func TestWrite2_2(t *testing.T) { // want is handwritten translation of the official example YAML SPDX v2.2 document into a Go struct. // We expect that the result of parsing the official document should be this value. // We expect that the result of writing this struct should match the official example document. -var want = spdx.Document2_2{ +var want = v2_2.Document{ DataLicense: "CC0-1.0", SPDXVersion: "SPDX-2.2", SPDXIdentifier: "SPDXRef-DOCUMENT", DocumentName: "SPDX-Tools-v2.0", DocumentNamespace: "http://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301", - CreationInfo: &spdx.CreationInfo2_2{ + CreationInfo: &v2_2.CreationInfo{ LicenseListVersion: "3.9", - Creators: []spdx.Creator{ + Creators: []common.Creator{ {CreatorType: "Tool", Creator: "LicenseFind-1.0"}, {CreatorType: "Organization", Creator: "ExampleCodeInspect ()"}, {CreatorType: "Person", Creator: "Jane Doe ()"}, @@ -75,17 +77,17 @@ var want = spdx.Document2_2{ CreatorComment: "This package has been shipped in source and binary form.\nThe binaries were created with gcc 4.5.1 and expect to link to\ncompatible system run time libraries.", }, DocumentComment: "This document was created using SPDX 2.0 using licenses from the web site.", - ExternalDocumentReferences: []spdx.ExternalDocumentRef2_2{ + ExternalDocumentReferences: []v2_2.ExternalDocumentRef{ { DocumentRefID: "DocumentRef-spdx-tool-1.2", URI: "http://spdx.org/spdxdocs/spdx-tools-v1.2-3F2504E0-4F89-41D3-9A0C-0305E82C3301", - Checksum: spdx.Checksum{ - Algorithm: spdx.SHA1, + Checksum: common.Checksum{ + Algorithm: common.SHA1, Value: "d6a770ba38583ed4bb4525bd96e50461655d2759", }, }, }, - OtherLicenses: []*spdx.OtherLicense2_2{ + OtherLicenses: []*v2_2.OtherLicense{ { LicenseIdentifier: "LicenseRef-1", ExtractedText: "/*\n * (c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * 3. The name of the author may not be used to endorse or promote products\n * derived from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\n * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*/", @@ -116,9 +118,9 @@ var want = spdx.Document2_2{ LicenseComment: "This is tye CyperNeko License", }, }, - Annotations: []*spdx.Annotation2_2{ + Annotations: []*v2_2.Annotation{ { - Annotator: spdx.Annotator{ + Annotator: common.Annotator{ Annotator: "Jane Doe ()", AnnotatorType: "Person", }, @@ -127,7 +129,7 @@ var want = spdx.Document2_2{ AnnotationComment: "Document level annotation", }, { - Annotator: spdx.Annotator{ + Annotator: common.Annotator{ Annotator: "Joe Reviewer", AnnotatorType: "Person", }, @@ -136,7 +138,7 @@ var want = spdx.Document2_2{ AnnotationComment: "This is just an example. Some of the non-standard licenses look like they are actually BSD 3 clause licenses", }, { - Annotator: spdx.Annotator{ + Annotator: common.Annotator{ Annotator: "Suzanne Reviewer", AnnotatorType: "Person", }, @@ -145,27 +147,27 @@ var want = spdx.Document2_2{ AnnotationComment: "Another example reviewer.", }, }, - Packages: []*spdx.Package2_2{ + Packages: []*v2_2.Package{ { PackageName: "glibc", PackageSPDXIdentifier: "SPDXRef-Package", PackageVersion: "2.11.1", PackageFileName: "glibc-2.11.1.tar.gz", - PackageSupplier: &spdx.Supplier{ + PackageSupplier: &common.Supplier{ Supplier: "Jane Doe (jane.doe@example.com)", SupplierType: "Person", }, - PackageOriginator: &spdx.Originator{ + PackageOriginator: &common.Originator{ Originator: "ExampleCodeInspect (contact@example.com)", OriginatorType: "Organization", }, PackageDownloadLocation: "http://ftp.gnu.org/gnu/glibc/glibc-ports-2.15.tar.gz", FilesAnalyzed: true, - PackageVerificationCode: spdx.PackageVerificationCode{ + PackageVerificationCode: common.PackageVerificationCode{ Value: "d6a770ba38583ed4bb4525bd96e50461655d2758", ExcludedFiles: []string{"./package.spdx"}, }, - PackageChecksums: []spdx.Checksum{ + PackageChecksums: []common.Checksum{ { Algorithm: "MD5", Value: "624c1abb3664f4b35547e7c73864ad24", @@ -193,7 +195,7 @@ var want = spdx.Document2_2{ PackageSummary: "GNU C library.", PackageDescription: "The GNU C Library defines functions that are specified by the ISO C standard, as well as additional features specific to POSIX and other derivatives of the Unix operating system, and extensions specific to GNU systems.", PackageComment: "", - PackageExternalReferences: []*spdx.PackageExternalReference2_2{ + PackageExternalReferences: []*v2_2.PackageExternalReference{ { Category: "SECURITY", RefType: "cpe23Type", @@ -210,9 +212,9 @@ var want = spdx.Document2_2{ "The GNU C Library is free software. See the file COPYING.LIB for copying conditions, and LICENSES for notices about a few contributions that require these additional notices to be distributed. License copyright years may be listed using range notation, e.g., 1996-2015, indicating that every year in the range, inclusive, is a copyrightable year that would otherwise be listed individually.", }, Files: nil, - Annotations: []spdx.Annotation2_2{ + Annotations: []v2_2.Annotation{ { - Annotator: spdx.Annotator{ + Annotator: common.Annotator{ Annotator: "Package Commenter", AnnotatorType: "Person", }, @@ -237,7 +239,7 @@ var want = spdx.Document2_2{ PackageSPDXIdentifier: "SPDXRef-fromDoap-0", PackageCopyrightText: "NOASSERTION", PackageDownloadLocation: "https://search.maven.org/remotecontent?filepath=org/apache/jena/apache-jena/3.12.0/apache-jena-3.12.0.tar.gz", - PackageExternalReferences: []*spdx.PackageExternalReference2_2{ + PackageExternalReferences: []*v2_2.PackageExternalReference{ { Category: "PACKAGE_MANAGER", RefType: "purl", @@ -252,7 +254,7 @@ var want = spdx.Document2_2{ }, { PackageSPDXIdentifier: "SPDXRef-Saxon", - PackageChecksums: []spdx.Checksum{ + PackageChecksums: []common.Checksum{ { Algorithm: "SHA1", Value: "85ed0817af83a24ad8da68c2b5094de69833983c", @@ -271,14 +273,14 @@ var want = spdx.Document2_2{ PackageVersion: "8.8", }, }, - Files: []*spdx.File2_2{ + Files: []*v2_2.File{ { FileName: "./src/org/spdx/parser/DOAPProject.java", FileSPDXIdentifier: "SPDXRef-DoapSource", FileTypes: []string{ "SOURCE", }, - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { Algorithm: "SHA1", Value: "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", @@ -299,7 +301,7 @@ var want = spdx.Document2_2{ }, { FileSPDXIdentifier: "SPDXRef-CommonsLangSrc", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { Algorithm: "SHA1", Value: "c2b4e1c67a2d28fced849ee1bb76e7391b93f125", @@ -316,7 +318,7 @@ var want = spdx.Document2_2{ }, { FileSPDXIdentifier: "SPDXRef-JenaLib", - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { Algorithm: "SHA1", Value: "3ab4e1c67a2d28fced849ee1bb76e7391b93f125", @@ -333,9 +335,9 @@ var want = spdx.Document2_2{ }, { FileSPDXIdentifier: "SPDXRef-File", - Annotations: []spdx.Annotation2_2{ + Annotations: []v2_2.Annotation{ { - Annotator: spdx.Annotator{ + Annotator: common.Annotator{ Annotator: "File Commenter", AnnotatorType: "Person", }, @@ -344,7 +346,7 @@ var want = spdx.Document2_2{ AnnotationComment: "File level annotation", }, }, - Checksums: []spdx.Checksum{ + Checksums: []common.Checksum{ { Algorithm: "SHA1", Value: "d6a770ba38583ed4bb4525bd96e50461655d2758", @@ -365,27 +367,27 @@ var want = spdx.Document2_2{ FileNotice: "Copyright (c) 2001 Aaron Lehmann aaroni@vitelus.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the �Software�), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: \nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED �AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", }, }, - Snippets: []spdx.Snippet2_2{ + Snippets: []v2_2.Snippet{ { SnippetSPDXIdentifier: "SPDXRef-Snippet", SnippetFromFileSPDXIdentifier: "SPDXRef-DoapSource", - Ranges: []spdx.SnippetRange{ + Ranges: []common.SnippetRange{ { - StartPointer: spdx.SnippetRangePointer{ + StartPointer: common.SnippetRangePointer{ Offset: 310, FileSPDXIdentifier: "SPDXRef-DoapSource", }, - EndPointer: spdx.SnippetRangePointer{ + EndPointer: common.SnippetRangePointer{ Offset: 420, FileSPDXIdentifier: "SPDXRef-DoapSource", }, }, { - StartPointer: spdx.SnippetRangePointer{ + StartPointer: common.SnippetRangePointer{ LineNumber: 5, FileSPDXIdentifier: "SPDXRef-DoapSource", }, - EndPointer: spdx.SnippetRangePointer{ + EndPointer: common.SnippetRangePointer{ LineNumber: 23, FileSPDXIdentifier: "SPDXRef-DoapSource", }, @@ -399,50 +401,50 @@ var want = spdx.Document2_2{ SnippetName: "from linux kernel", }, }, - Relationships: []*spdx.Relationship2_2{ + Relationships: []*v2_2.Relationship{ { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "Package"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "Package"), Relationship: "CONTAINS", }, { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("spdx-tool-1.2", "ToolsElement"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("spdx-tool-1.2", "ToolsElement"), Relationship: "COPY_OF", }, { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "File"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "File"), Relationship: "DESCRIBES", }, { - RefA: spdx.MakeDocElementID("", "DOCUMENT"), - RefB: spdx.MakeDocElementID("", "Package"), + RefA: common.MakeDocElementID("", "DOCUMENT"), + RefB: common.MakeDocElementID("", "Package"), Relationship: "DESCRIBES", }, { - RefA: spdx.MakeDocElementID("", "Package"), - RefB: spdx.MakeDocElementID("", "JenaLib"), + RefA: common.MakeDocElementID("", "Package"), + RefB: common.MakeDocElementID("", "JenaLib"), Relationship: "CONTAINS", }, { - RefA: spdx.MakeDocElementID("", "Package"), - RefB: spdx.MakeDocElementID("", "Saxon"), + RefA: common.MakeDocElementID("", "Package"), + RefB: common.MakeDocElementID("", "Saxon"), Relationship: "DYNAMIC_LINK", }, { - RefA: spdx.MakeDocElementID("", "CommonsLangSrc"), - RefB: spdx.MakeDocElementSpecial("NOASSERTION"), + RefA: common.MakeDocElementID("", "CommonsLangSrc"), + RefB: common.MakeDocElementSpecial("NOASSERTION"), Relationship: "GENERATED_FROM", }, { - RefA: spdx.MakeDocElementID("", "JenaLib"), - RefB: spdx.MakeDocElementID("", "Package"), + RefA: common.MakeDocElementID("", "JenaLib"), + RefB: common.MakeDocElementID("", "Package"), Relationship: "CONTAINS", }, { - RefA: spdx.MakeDocElementID("", "File"), - RefB: spdx.MakeDocElementID("", "fromDoap-0"), + RefA: common.MakeDocElementID("", "File"), + RefB: common.MakeDocElementID("", "fromDoap-0"), Relationship: "GENERATED_FROM", }, },