diff --git a/cmd/detectExecuteScan.go b/cmd/detectExecuteScan.go index db2c4956e..4df43c96f 100644 --- a/cmd/detectExecuteScan.go +++ b/cmd/detectExecuteScan.go @@ -127,16 +127,11 @@ func getDetectScript(config detectExecuteScanOptions, utils detectUtils) error { } func addDetectArgs(args []string, config detectExecuteScanOptions, utils detectUtils) ([]string, error) { - - coordinates := versioning.Coordinates{ - Version: config.Version, - } - detectVersionName := config.CustomScanVersion if len(detectVersionName) > 0 { log.Entry().Infof("Using custom version: %v", detectVersionName) } else { - detectVersionName = versioning.ApplyVersioningModel(config.VersioningModel, coordinates) + detectVersionName = versioning.ApplyVersioningModel(config.VersioningModel, config.Version) } //Split on spaces, the scanPropeties, so that each property is available as a single string //instead of all properties being part of a single string diff --git a/cmd/sonarExecuteScan.go b/cmd/sonarExecuteScan.go index a39147e0d..540b6eb05 100644 --- a/cmd/sonarExecuteScan.go +++ b/cmd/sonarExecuteScan.go @@ -128,7 +128,7 @@ func runSonar(config sonarExecuteScanOptions, client piperhttp.Downloader, runne if len(version) > 0 { log.Entry().Infof("Using custom version: %v", version) } else { - version = versioning.ApplyVersioningModel(config.VersioningModel, versioning.Coordinates{Version: config.Version}) + version = versioning.ApplyVersioningModel(config.VersioningModel, config.Version) } sonar.addOption("sonar.projectVersion=" + version) } diff --git a/pkg/versioning/descriptorUtils.go b/pkg/versioning/descriptorUtils.go index 60fd8b563..84de5b24d 100644 --- a/pkg/versioning/descriptorUtils.go +++ b/pkg/versioning/descriptorUtils.go @@ -25,6 +25,6 @@ func DetermineProjectCoordinates(nameTemplate, versionScheme string, gav Coordin log.Entry().Warnf("Unable to resolve project name: %v", err) } - projectVersion := ApplyVersioningModel(versionScheme, gav) + projectVersion := ApplyVersioningModel(versionScheme, gav.Version) return projectName, projectVersion } diff --git a/pkg/versioning/versioningModel.go b/pkg/versioning/versioningModel.go index 5b8a893d9..2dd37a00c 100644 --- a/pkg/versioning/versioningModel.go +++ b/pkg/versioning/versioningModel.go @@ -24,7 +24,7 @@ const ( VersioningModelMajor string = "major" ) -func ApplyVersioningModel(model string, projectCoordinates Coordinates) string { +func ApplyVersioningModel(model, projectVersion string) string { var versioningScheme string switch model { @@ -40,7 +40,7 @@ func ApplyVersioningModel(model string, projectCoordinates Coordinates) string { log.Entry().Warnf("versioning model not supported: %s", model) } - version, err := piperutils.ExecuteTemplateFunctions(versioningScheme, sprig.HermeticTxtFuncMap(), projectCoordinates) + version, err := piperutils.ExecuteTemplateFunctions(versioningScheme, sprig.HermeticTxtFuncMap(), Coordinates{Version: projectVersion}) if err != nil { log.Entry().Warnf("unable to resolve project version: %v", err) } diff --git a/pkg/versioning/versioningModel_test.go b/pkg/versioning/versioningModel_test.go index 9a446800f..73aee043f 100644 --- a/pkg/versioning/versioningModel_test.go +++ b/pkg/versioning/versioningModel_test.go @@ -7,23 +7,23 @@ import ( func Test_applyVersioningModel(t *testing.T) { type args struct { model string - version Coordinates + version string } tests := []struct { name string args args want string }{ - {"maven - major", args{VersioningModelMajor, Coordinates{Version: "1.2.3-7864387648746"}}, "1"}, - {"maven - major-minor", args{VersioningModelMajorMinor, Coordinates{Version: "1.2.3-7864387648746"}}, "1.2"}, - {"maven - semantic", args{VersioningModelSemantic, Coordinates{Version: "1.2.3-7864387648746"}}, "1.2.3"}, - {"maven - full", args{VersioningModelFull, Coordinates{Version: "1.2.3-7864387648746"}}, "1.2.3-7864387648746"}, - {"python - major-minor", args{VersioningModelMajorMinor, Coordinates{Version: "2.2.3.20200101"}}, "2.2"}, - {"leading zero", args{VersioningModelMajor, Coordinates{Version: "0.0.1"}}, "0"}, - {"trailing zero", args{VersioningModelMajorMinor, Coordinates{Version: "2.0"}}, "2.0"}, - {"invalid - unknown versioning model", args{"snapshot", Coordinates{Version: "1.2.3-SNAPSHOT"}}, ""}, - {"invalid - incorrect version", args{VersioningModelMajor, Coordinates{Version: ".2.3"}}, ""}, - {"invalid - version to short", args{VersioningModelSemantic, Coordinates{Version: "1.2"}}, "1.2."}, + {"maven - major", args{VersioningModelMajor, "1.2.3-7864387648746"}, "1"}, + {"maven - major-minor", args{VersioningModelMajorMinor, "1.2.3-7864387648746"}, "1.2"}, + {"maven - semantic", args{VersioningModelSemantic, "1.2.3-7864387648746"}, "1.2.3"}, + {"maven - full", args{VersioningModelFull, "1.2.3-7864387648746"}, "1.2.3-7864387648746"}, + {"python - major-minor", args{VersioningModelMajorMinor, "2.2.3.20200101"}, "2.2"}, + {"leading zero", args{VersioningModelMajor, "0.0.1"}, "0"}, + {"trailing zero", args{VersioningModelMajorMinor, "2.0"}, "2.0"}, + {"invalid - unknown versioning model", args{"snapshot", "1.2.3-SNAPSHOT"}, ""}, + {"invalid - incorrect version", args{VersioningModelMajor, ".2.3"}, ""}, + {"invalid - version to short", args{VersioningModelSemantic, "1.2"}, "1.2."}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {