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

feat(whitesourceExecuteScan) allow custom maven arguments (#2735)

* feat(whitesourceExecuteScan) allow custom maven arguments

* remove comment

Co-authored-by: Sven Merk <33895725+nevskrem@users.noreply.github.com>
This commit is contained in:
Oliver Nocon 2021-04-01 14:17:15 +02:00 committed by GitHub
parent 97b3a23336
commit 0696f64ecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -19,6 +19,7 @@ type ConfigOption struct {
Value interface{}
OmitIfPresent string
Force bool
Append bool
}
// ConfigOptions contains a list of config options (ConfigOption)
@ -73,8 +74,17 @@ func (c *ConfigOptions) updateConfig(originalConfig *map[string]string) map[stri
if len(cOpt.OmitIfPresent) > 0 {
dependentValue = newConfig[cOpt.OmitIfPresent]
}
if len(dependentValue) == 0 && (cOpt.Force || len(newConfig[cOpt.Name]) == 0) {
newConfig[cOpt.Name] = fmt.Sprint(cOpt.Value)
if len(dependentValue) == 0 {
if cOpt.Append {
if len(newConfig[cOpt.Name]) > 0 {
newConfig[cOpt.Name] = fmt.Sprintf("%v %v", newConfig[cOpt.Name], cOpt.Value)
} else {
newConfig[cOpt.Name] = fmt.Sprint(cOpt.Value)
}
} else if cOpt.Force || len(newConfig[cOpt.Name]) == 0 {
newConfig[cOpt.Name] = fmt.Sprint(cOpt.Value)
}
}
}
return newConfig
@ -222,7 +232,7 @@ func (c *ConfigOptions) addBuildToolDefaults(config *ScanOptions, utils Utils) e
mvnAdditionalArguments = append(mvnAdditionalArguments, mvnProjectExcludes(config.BuildDescriptorExcludeList, utils)...)
if len(mvnAdditionalArguments) > 0 {
*c = append(*c, ConfigOption{Name: "maven.additionalArguments", Value: strings.Join(mvnAdditionalArguments, " "), Force: true})
*c = append(*c, ConfigOption{Name: "maven.additionalArguments", Value: strings.Join(mvnAdditionalArguments, " "), Append: true})
}
}

View File

@ -63,6 +63,8 @@ func TestUpdateConfig(t *testing.T) {
"not_forced": "not_forced_original",
"dont_omit_forced": "dont_omit_forced_original",
"dont_omit_not_forced": "dont_omit_not_forced_original",
"append": "original_value appended by",
"append_empty": "",
}
testConfig := ConfigOptions{
{Name: "non_existing_forced", Value: "non_existing_forced_val", Force: true},
@ -73,6 +75,8 @@ func TestUpdateConfig(t *testing.T) {
{Name: "dont_omit", Value: "dont_omit_val", OmitIfPresent: "dependent_notExisting"},
{Name: "dont_omit_forced", Value: "dont_omit_forced_val", OmitIfPresent: "dependent_notExisting", Force: true},
{Name: "dont_omit_not_forced", Value: "dont_omit_not_forced_val", OmitIfPresent: "dependent_notExisting", Force: false},
{Name: "append", Value: "appended_val", Append: true},
{Name: "append_empty", Value: "appended_val", Append: true},
}
updatedConfig := testConfig.updateConfig(&originalConfig)
@ -86,6 +90,8 @@ func TestUpdateConfig(t *testing.T) {
assert.Equal(t, "dont_omit_val", updatedConfig["dont_omit"])
assert.Equal(t, "dont_omit_forced_val", updatedConfig["dont_omit_forced"])
assert.Equal(t, "dont_omit_not_forced_original", updatedConfig["dont_omit_not_forced"])
assert.Equal(t, "original_value appended by appended_val", updatedConfig["append"])
assert.Equal(t, "appended_val", updatedConfig["append_empty"])
}
func TestAddGeneralDefaults(t *testing.T) {
@ -211,7 +217,7 @@ func TestAddBuildToolDefaults(t *testing.T) {
}
utilsMock.AddFile("unit-tests/pom.xml", []byte("dummy"))
testConfig.addBuildToolDefaults(&whitesourceConfig, utilsMock)
assert.Contains(t, testConfig, ConfigOption{Name: "maven.additionalArguments", Value: "--global-settings global-settings.xml --settings project-settings.xml --projects !unit-tests", Force: true})
assert.Contains(t, testConfig, ConfigOption{Name: "maven.additionalArguments", Value: "--global-settings global-settings.xml --settings project-settings.xml --projects !unit-tests", Append: true})
})
t.Run("Docker - default", func(t *testing.T) {