Skip to content

Commit 82a2dd8

Browse files
Fix/lifecycle (#4)
* support lifecyclescope;2;13~ * complete support for core profile * missing classes from software profile * Security profile: * Fix missing licensing info * remaining classes
1 parent 9b11517 commit 82a2dd8

File tree

6 files changed

+1610
-205
lines changed

6 files changed

+1610
-205
lines changed

examplemaven-0.0.1.spdx3.json

Lines changed: 394 additions & 0 deletions
Large diffs are not rendered by default.

examples/spdx-lister/main.go

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func printDocumentInfo(doc *parse.Document, showFiles bool) {
7070
fmt.Printf(" SPDX ID: %s\n", doc.SpdxDocument.SpdxID)
7171
if doc.SpdxDocument.DataLicense != nil {
7272
// Resolve the license reference to get the actual name
73-
if lic := doc.GetLicenseByID(doc.SpdxDocument.DataLicense.SpdxID); lic != nil && lic.Name != "" {
73+
if lic := doc.GetAnyLicenseInfoByID(doc.SpdxDocument.DataLicense.SpdxID); lic != nil && lic.Name != "" {
7474
fmt.Printf(" Data License: %s\n", lic.Name)
7575
} else if doc.SpdxDocument.DataLicense.Name != "" {
7676
fmt.Printf(" Data License: %s\n", doc.SpdxDocument.DataLicense.Name)
@@ -146,8 +146,8 @@ func printDocumentInfo(doc *parse.Document, showFiles bool) {
146146
fmt.Printf(" Persons: %d\n", len(doc.Persons))
147147
fmt.Printf(" SoftwareAgents:%d\n", len(doc.SoftwareAgents))
148148
fmt.Printf(" Tools: %d\n", len(doc.Tools))
149-
fmt.Printf(" Licenses: %d\n", len(doc.Licenses))
150-
fmt.Printf(" IndividualElements: %d\n", len(doc.IndividualElements))
149+
fmt.Printf(" Licenses: %d\n", len(doc.AnyLicenseInfos)+len(doc.ConjunctiveLicenseSets)+len(doc.CustomLicenses)+len(doc.CustomLicenseAdditions)+len(doc.DisjunctiveLicenseSets)+len(doc.IndividualLicensingInfos)+len(doc.ListedLicenses)+len(doc.ListedLicenseExceptions)+len(doc.LicenseExpressions)+len(doc.OrLaterOperators)+len(doc.SimpleLicensingTexts)+len(doc.WithAdditionOperators))
150+
151151
fmt.Printf(" IndividualLicensingInfos: %d\n", len(doc.IndividualLicensingInfos))
152152
fmt.Println()
153153

@@ -442,14 +442,7 @@ func printDocumentInfo(doc *parse.Document, showFiles bool) {
442442
fmt.Println()
443443
}
444444

445-
// Individual Elements
446-
if len(doc.IndividualElements) > 0 {
447-
fmt.Println("Individual Elements:")
448-
for _, ie := range doc.IndividualElements {
449-
fmt.Printf(" - %s\n", ie.Name)
450-
}
451-
fmt.Println()
452-
}
445+
453446

454447
// Individual Licensing Infos
455448
if len(doc.IndividualLicensingInfos) > 0 {
@@ -641,11 +634,7 @@ func findElementsCreatedByAgent(doc *parse.Document, agentID string) []string {
641634
elementIDs = append(elementIDs, tool.SpdxID)
642635
}
643636
}
644-
for _, ie := range doc.IndividualElements {
645-
if isCreatedBy(&ie.CreationInfo) {
646-
elementIDs = append(elementIDs, ie.SpdxID)
647-
}
648-
}
637+
649638
for _, ili := range doc.IndividualLicensingInfos {
650639
if isCreatedBy(&ili.CreationInfo) {
651640
elementIDs = append(elementIDs, ili.SpdxID)
@@ -758,18 +747,11 @@ func getElementInfo(doc *parse.Document, elemID string) string {
758747
}
759748

760749
// Check licenses
761-
for _, lic := range doc.Licenses {
762-
if lic.SpdxID == elemID {
763-
return fmt.Sprintf("%s (License, ID: %s)", lic.Name, elemID)
764-
}
750+
if lic := doc.GetAnyLicenseInfoByID(elemID); lic != nil {
751+
return fmt.Sprintf("%s (License, ID: %s)", lic.Name, elemID)
765752
}
766753

767-
// Check individual elements
768-
for _, ie := range doc.IndividualElements {
769-
if ie.SpdxID == elemID {
770-
return fmt.Sprintf("%s (IndividualElement, ID: %s)", ie.Name, elemID)
771-
}
772-
}
754+
773755

774756
// Check document itself
775757
if doc.SpdxDocument != nil && doc.SpdxDocument.SpdxID == elemID {

parse/document.go

Lines changed: 100 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,61 @@ type Document struct {
88
Graph []spdx.Element `json:"-"` // Parsed elements from @graph
99

1010
// Parsed and categorized elements
11-
SpdxDocument *spdx.SpdxDocument
12-
Packages []*spdx.Package
13-
Files []*spdx.File
14-
Snippets []*spdx.Snippet
15-
Relationships []*spdx.Relationship
16-
Annotations []*spdx.Annotation
17-
ExternalMaps []*spdx.ExternalMap
18-
CreationInfo *spdx.CreationInfo
19-
Organizations []*spdx.Organization
20-
Persons []*spdx.Person
21-
SoftwareAgents []*spdx.SoftwareAgent
22-
Tools []*spdx.Tool
23-
Licenses []*spdx.AnyLicenseInfo
24-
IndividualElements []*spdx.IndividualElement
11+
SpdxDocument *spdx.SpdxDocument
12+
Packages []*spdx.Package
13+
Files []*spdx.File
14+
Snippets []*spdx.Snippet
15+
Relationships []*spdx.Relationship
16+
LifecycleScopedRelationships []*spdx.LifecycleScopedRelationship
17+
Annotations []*spdx.Annotation
18+
ExternalMaps []*spdx.ExternalMap
19+
CreationInfo *spdx.CreationInfo
20+
Organizations []*spdx.Organization
21+
Persons []*spdx.Person
22+
SoftwareAgents []*spdx.SoftwareAgent
23+
Tools []*spdx.Tool
24+
Bundles []*spdx.Bundle
25+
Boms []*spdx.Bom
26+
DictionaryEntries []*spdx.DictionaryEntry
27+
Hashes []*spdx.Hash
28+
PackageVerificationCodes []*spdx.PackageVerificationCode
29+
// Licensing-related elements
30+
AnyLicenseInfos []*spdx.AnyLicenseInfo
31+
ConjunctiveLicenseSets []*spdx.ConjunctiveLicenseSet
32+
CustomLicenses []*spdx.CustomLicense
33+
CustomLicenseAdditions []*spdx.CustomLicenseAddition
34+
DisjunctiveLicenseSets []*spdx.DisjunctiveLicenseSet
2535
IndividualLicensingInfos []*spdx.IndividualLicensingInfo
36+
ListedLicenses []*spdx.ListedLicense
37+
ListedLicenseExceptions []*spdx.ListedLicenseException
38+
LicenseExpressions []*spdx.LicenseExpression
39+
OrLaterOperators []*spdx.OrLaterOperator
40+
SimpleLicensingTexts []*spdx.SimpleLicensingText
41+
WithAdditionOperators []*spdx.WithAdditionOperator
42+
43+
// Security-related elements
44+
Vulnerabilities []*spdx.Vulnerability
45+
CvssV2VulnAssessments []*spdx.CvssV2VulnAssessmentRelationship
46+
CvssV3VulnAssessments []*spdx.CvssV3VulnAssessmentRelationship
47+
CvssV4VulnAssessments []*spdx.CvssV4VulnAssessmentRelationship
48+
EpssVulnAssessments []*spdx.EpssVulnAssessmentRelationship
49+
SsvcVulnAssessments []*spdx.SsvcVulnAssessmentRelationship
50+
ExploitCatalogVulnAssessments []*spdx.ExploitCatalogVulnAssessmentRelationship
51+
VexAffectedVulnAssessments []*spdx.VexAffectedVulnAssessmentRelationship
52+
VexFixedVulnAssessments []*spdx.VexFixedVulnAssessmentRelationship
53+
VexNotAffectedVulnAssessments []*spdx.VexNotAffectedVulnAssessmentRelationship
54+
VexUnderInvestigationVulnAssessments []*spdx.VexUnderInvestigationVulnAssessmentRelationship
55+
56+
// AI-related elements
57+
AiPackages []*spdx.AIPackage
58+
EnergyConsumptions []*spdx.EnergyConsumption
59+
EnergyConsumptionDescriptions []*spdx.EnergyConsumptionDescription
60+
61+
// Dataset-related elements
62+
DatasetPackages []*spdx.DatasetPackage
63+
64+
// Build-related elements
65+
Builds []*spdx.Build
2666

2767
// All elements indexed by SPDX ID
2868
ElementsByID map[string]interface{}
@@ -32,13 +72,45 @@ type Document struct {
3272
RelationshipsToIndex map[string][]*spdx.Relationship
3373

3474
// Element type indexes for O(1) lookups
35-
PackagesByID map[string]*spdx.Package
36-
FilesByID map[string]*spdx.File
37-
OrganizationsByID map[string]*spdx.Organization
38-
PersonsByID map[string]*spdx.Person
39-
SoftwareAgentsByID map[string]*spdx.SoftwareAgent
40-
ToolsByID map[string]*spdx.Tool
41-
LicensesByID map[string]*spdx.AnyLicenseInfo
75+
PackagesByID map[string]*spdx.Package
76+
FilesByID map[string]*spdx.File
77+
OrganizationsByID map[string]*spdx.Organization
78+
PersonsByID map[string]*spdx.Person
79+
SoftwareAgentsByID map[string]*spdx.SoftwareAgent
80+
ToolsByID map[string]*spdx.Tool
81+
AnyLicenseInfosByID map[string]*spdx.AnyLicenseInfo
82+
ConjunctiveLicenseSetsByID map[string]*spdx.ConjunctiveLicenseSet
83+
CustomLicensesByID map[string]*spdx.CustomLicense
84+
CustomLicenseAdditionsByID map[string]*spdx.CustomLicenseAddition
85+
DisjunctiveLicenseSetsByID map[string]*spdx.DisjunctiveLicenseSet
86+
IndividualLicensingInfosByID map[string]*spdx.IndividualLicensingInfo
87+
ListedLicensesByID map[string]*spdx.ListedLicense
88+
ListedLicenseExceptionsByID map[string]*spdx.ListedLicenseException
89+
LicenseExpressionsByID map[string]*spdx.LicenseExpression
90+
OrLaterOperatorsByID map[string]*spdx.OrLaterOperator
91+
SimpleLicensingTextsByID map[string]*spdx.SimpleLicensingText
92+
WithAdditionOperatorsByID map[string]*spdx.WithAdditionOperator
93+
VulnerabilitiesByID map[string]*spdx.Vulnerability
94+
CvssV2VulnAssessmentsByID map[string]*spdx.CvssV2VulnAssessmentRelationship
95+
CvssV3VulnAssessmentsByID map[string]*spdx.CvssV3VulnAssessmentRelationship
96+
CvssV4VulnAssessmentsByID map[string]*spdx.CvssV4VulnAssessmentRelationship
97+
EpssVulnAssessmentsByID map[string]*spdx.EpssVulnAssessmentRelationship
98+
SsvcVulnAssessmentsByID map[string]*spdx.SsvcVulnAssessmentRelationship
99+
ExploitCatalogVulnAssessmentsByID map[string]*spdx.ExploitCatalogVulnAssessmentRelationship
100+
VexAffectedVulnAssessmentsByID map[string]*spdx.VexAffectedVulnAssessmentRelationship
101+
VexFixedVulnAssessmentsByID map[string]*spdx.VexFixedVulnAssessmentRelationship
102+
VexNotAffectedVulnAssessmentsByID map[string]*spdx.VexNotAffectedVulnAssessmentRelationship
103+
VexUnderInvestigationVulnAssessmentsByID map[string]*spdx.VexUnderInvestigationVulnAssessmentRelationship
104+
// AI-related maps
105+
AiPackagesByID map[string]*spdx.AIPackage
106+
EnergyConsumptionsByID map[string]*spdx.EnergyConsumption
107+
EnergyConsumptionDescriptionsByID map[string]*spdx.EnergyConsumptionDescription
108+
109+
// Dataset-related maps
110+
DatasetPackagesByID map[string]*spdx.DatasetPackage
111+
112+
// Build-related maps
113+
BuildsByID map[string]*spdx.Build
42114
}
43115

44116
// GetName returns the document name
@@ -231,13 +303,13 @@ func (d *Document) GetLicensesFor(spdxID string) *LicenseInfo {
231303
for _, rel := range d.GetRelationshipsFrom(spdxID) {
232304
if rel.IsConcludedLicense() {
233305
for _, to := range rel.To {
234-
if lic := d.GetLicenseByID(to.GetSpdxID()); lic != nil {
306+
if lic := d.GetAnyLicenseInfoByID(to.GetSpdxID()); lic != nil {
235307
info.ConcludedLicenses = append(info.ConcludedLicenses, lic)
236308
}
237309
}
238310
} else if rel.IsDeclaredLicense() {
239311
for _, to := range rel.To {
240-
if lic := d.GetLicenseByID(to.GetSpdxID()); lic != nil {
312+
if lic := d.GetAnyLicenseInfoByID(to.GetSpdxID()); lic != nil {
241313
info.DeclaredLicenses = append(info.DeclaredLicenses, lic)
242314
}
243315
}
@@ -246,14 +318,14 @@ func (d *Document) GetLicensesFor(spdxID string) *LicenseInfo {
246318
return info
247319
}
248320

249-
// GetLicenseByID returns a license by its SPDX ID.
250-
func (d *Document) GetLicenseByID(spdxID string) *spdx.AnyLicenseInfo {
251-
if d.LicensesByID != nil {
252-
if lic := d.LicensesByID[spdxID]; lic != nil {
321+
// GetAnyLicenseInfoByID returns a license by its SPDX ID.
322+
func (d *Document) GetAnyLicenseInfoByID(spdxID string) *spdx.AnyLicenseInfo {
323+
if d.AnyLicenseInfosByID != nil {
324+
if lic := d.AnyLicenseInfosByID[spdxID]; lic != nil {
253325
return lic
254326
}
255327
} else {
256-
for _, lic := range d.Licenses {
328+
for _, lic := range d.AnyLicenseInfos {
257329
if lic.SpdxID == spdxID {
258330
return lic
259331
}

0 commit comments

Comments
 (0)