1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-05 15:15:44 +02:00

feat(versioning): add re-use function for proper Scan versioning (#2544)

* feat(versioning): add re-use function for proper Scan versioning

addresses #1846

* add missing comment

Co-authored-by: Sven Merk <33895725+nevskrem@users.noreply.github.com>
This commit is contained in:
Oliver Nocon 2021-02-08 12:18:36 +01:00 committed by GitHub
parent 5f053d1c32
commit f2f5dbecb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -18,7 +18,17 @@ const (
SchemeFullVersion = "{{.Version}}"
)
// DetermineProjectCoordinates resolve the coordinates of the project for use in 3rd party scan tools
// DetermineProjectCoordinatesWithCustomVersion resolves the coordinates of the project for use in 3rd party scan tools
// It considers a custom version if provided instead of using the GAV version adapted according to the versionScheme
func DetermineProjectCoordinatesWithCustomVersion(nameTemplate, versionScheme, customVersion string, gav Coordinates) (string, string) {
name, version := DetermineProjectCoordinates(nameTemplate, versionScheme, gav)
if len(customVersion) > 0 {
return name, customVersion
}
return name, version
}
// DetermineProjectCoordinates resolves the coordinates of the project for use in 3rd party scan tools
func DetermineProjectCoordinates(nameTemplate, versionScheme string, gav Coordinates) (string, string) {
projectName, err := piperutils.ExecuteTemplateFunctions(nameTemplate, sprig.HermeticTxtFuncMap(), gav)
if err != nil {

View File

@ -46,6 +46,23 @@ func (p *pipMock) GetCoordinates() (Coordinates, error) {
return &PipDescriptor{ArtifactID: p.artifactID, Version: p.version}, nil
}
func TestDetermineProjectCoordinatesWithCustomVersion(t *testing.T) {
nameTemplate := `{{list .GroupID .ArtifactID | join "-" | trimAll "-"}}`
t.Run("default", func(t *testing.T) {
gav, _ := (&mavenMock{groupID: "com.test.pkg", artifactID: "analyzer", version: "1.2.3"}).GetCoordinates()
name, version := DetermineProjectCoordinatesWithCustomVersion(nameTemplate, "major", "", gav)
assert.Equal(t, "com.test.pkg-analyzer", name, "Expected different project name")
assert.Equal(t, "1", version, "Expected different project version")
})
t.Run("custom", func(t *testing.T) {
gav, _ := (&mavenMock{groupID: "com.test.pkg", artifactID: "analyzer", version: "1.2.3"}).GetCoordinates()
_, version := DetermineProjectCoordinatesWithCustomVersion(nameTemplate, "major", "customVersion", gav)
assert.Equal(t, "customVersion", version, "Expected different project version")
})
}
func TestDetermineProjectCoordinates(t *testing.T) {
nameTemplate := `{{list .GroupID .ArtifactID | join "-" | trimAll "-"}}`