Skip to content

Commit

Permalink
fix: get purl arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Germanov committed Oct 30, 2024
1 parent b41f987 commit 201a9fa
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/mavenBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func createBuildArtifactsMetadata(config *mavenBuildOptions, commonPipelineEnvir
} else {
coordinate.BuildPath = filepath.Dir(match)
coordinate.URL = config.AltDeploymentRepositoryURL
coordinate.PURL = piperutils.GetPurl(match, mvnSimpleBomFilename+".xml")
coordinate.PURL = piperutils.GetPurl(filepath.Join(match, "/target/"+mvnSimpleBomFilename+".xml"))
buildCoordinates = append(buildCoordinates, coordinate)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/mtaBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func buildArtifactsMetadata(config mtaBuildOptions, commonPipelineEnvironment *m
Packaging: "mtar",
BuildPath: filepath.Dir(mtarPath),
URL: config.MtaDeploymentRepositoryURL,
PURL: piperutils.GetPurl(mtarPath, "sbom-gen/bom-mta.xml"),
PURL: piperutils.GetPurl(filepath.Join(mtarPath, "sbom-gen/bom-mta.xml")),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/npm/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (exec *Execute) publish(packageJSON, registry, username, password string, p
coordinate.BuildPath = filepath.Dir(packageJSON)
coordinate.URL = registry
coordinate.Packaging = "tgz"
coordinate.PURL = piperutils.GetPurl(packageJSON, npmBomFilename)
coordinate.PURL = piperutils.GetPurl(filepath.Join(packageJSON, npmBomFilename))

*buildCoordinates = append(*buildCoordinates, coordinate)
}
Expand Down
13 changes: 1 addition & 12 deletions pkg/piperutils/cyclonedxBom.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/xml"
"io"
"os"
"path/filepath"

"github.com/SAP/jenkins-library/pkg/log"
)
Expand Down Expand Up @@ -49,17 +48,7 @@ func GetBom(absoluteBomPath string) (Bom, error) {
return bom, nil
}

func GetPurl(filePath, bomFilename string) string {
bomFilePath := filepath.Join(filepath.Dir(filePath), bomFilename)
exists, err := FileExists(bomFilePath)
if err != nil {
log.Entry().Warnf("unable to check if bom file exists: %v", err)
return ""
}
if !exists {
log.Entry().Debugf("bom file doesn't exist and hence no pURL info: %v", bomFilePath)
return ""
}
func GetPurl(bomFilePath string) string {
bom, err := GetBom(bomFilePath)
if err != nil {
log.Entry().Warnf("unable to get bom metadata: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/piperutils/cyclonedxbom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestGetPurl(t *testing.T) {
filePath = "nonexistent.xml"
}

purl := GetPurl(filePath, "test.xml")
purl := GetPurl(filePath)
if purl != tt.expectedPurl {
t.Errorf("Expected PURL: %v, got: %v", tt.expectedPurl, purl)
}
Expand Down

0 comments on commit 201a9fa

Please sign in to comment.