Loading tools/compliance/cmd/sbom/sbom.go +26 −3 Original line number Diff line number Diff line Loading @@ -233,7 +233,7 @@ func getDownloadUrl(_ *context, pm *projectmetadata.ProjectMetadata) string { return url } // getProjectMetadata returns the project metadata for the target node // getProjectMetadata returns the optimal project metadata for the target node func getProjectMetadata(_ *context, pmix *projectmetadata.Index, tn *compliance.TargetNode) (*projectmetadata.ProjectMetadata, error) { pms, err := pmix.MetadataForProjects(tn.Projects()...) Loading @@ -244,8 +244,31 @@ func getProjectMetadata(_ *context, pmix *projectmetadata.Index, return nil, nil } // TO DO: skip first element if it doesn't have one of the three info needed return pms[0], nil // Getting the project metadata that contains most of the info needed for sbomGenerator score := -1 index := -1 for i := 0; i < len(pms); i++ { tempScore := 0 if pms[i].Name() != "" { tempScore += 1 } if pms[i].Version() != "" { tempScore += 1 } if pms[i].UrlsByTypeName().DownloadUrl() != "" { tempScore += 1 } if tempScore == score { if pms[i].Project() < pms[index].Project() { index = i } } else if tempScore > score { score = tempScore index = i } } return pms[index], nil } // sbomGenerator implements the spdx bom utility Loading tools/compliance/projectmetadata/projectmetadata.go +5 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,11 @@ func (pm *ProjectMetadata) String() string { return fmt.Sprintf("project: %q\n%s", pm.project, pm.proto.String()) } // Project returns the path to the directory containing the METADATA file func (pm *ProjectMetadata) Project() string { return pm.project } // ProjectName returns the name of the project. func (pm *ProjectMetadata) Name() string { return pm.proto.GetName() Loading Loading
tools/compliance/cmd/sbom/sbom.go +26 −3 Original line number Diff line number Diff line Loading @@ -233,7 +233,7 @@ func getDownloadUrl(_ *context, pm *projectmetadata.ProjectMetadata) string { return url } // getProjectMetadata returns the project metadata for the target node // getProjectMetadata returns the optimal project metadata for the target node func getProjectMetadata(_ *context, pmix *projectmetadata.Index, tn *compliance.TargetNode) (*projectmetadata.ProjectMetadata, error) { pms, err := pmix.MetadataForProjects(tn.Projects()...) Loading @@ -244,8 +244,31 @@ func getProjectMetadata(_ *context, pmix *projectmetadata.Index, return nil, nil } // TO DO: skip first element if it doesn't have one of the three info needed return pms[0], nil // Getting the project metadata that contains most of the info needed for sbomGenerator score := -1 index := -1 for i := 0; i < len(pms); i++ { tempScore := 0 if pms[i].Name() != "" { tempScore += 1 } if pms[i].Version() != "" { tempScore += 1 } if pms[i].UrlsByTypeName().DownloadUrl() != "" { tempScore += 1 } if tempScore == score { if pms[i].Project() < pms[index].Project() { index = i } } else if tempScore > score { score = tempScore index = i } } return pms[index], nil } // sbomGenerator implements the spdx bom utility Loading
tools/compliance/projectmetadata/projectmetadata.go +5 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,11 @@ func (pm *ProjectMetadata) String() string { return fmt.Sprintf("project: %q\n%s", pm.project, pm.proto.String()) } // Project returns the path to the directory containing the METADATA file func (pm *ProjectMetadata) Project() string { return pm.project } // ProjectName returns the name of the project. func (pm *ProjectMetadata) Name() string { return pm.proto.GetName() Loading