Skip to content

Commit

Permalink
fix(codeqlExecuteScan): handle spaces in path to maven settings file (#…
Browse files Browse the repository at this point in the history
…5037)

* added quotes for mvn settings path

* added logs

* removed logs, added excape symbol for spaces

* set quotes

* removed replacing

* changed quotes

* fixed tests

* removed extra log

---------

Co-authored-by: sumeet patil <sumeet.patil@sap.com>
  • Loading branch information
daskuznetsova and sumeetpatil authored Sep 12, 2024
1 parent af5b738 commit 085a8c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/codeqlExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func getMavenSettings(buildCmd string, config *codeqlExecuteScanOptions, utils c
return params
}
for i := 1; i < len(mvnParams); i += 2 {
params = fmt.Sprintf("%s %s=%s", params, mvnParams[i-1], mvnParams[i])
params = fmt.Sprintf("%s \"%s=%s\"", params, mvnParams[i-1], mvnParams[i])
}
}
return params
Expand Down
28 changes: 14 additions & 14 deletions cmd/codeqlExecuteScan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestGetMavenSettings(t *testing.T) {
params := getMavenSettings(buildCmd, &config, newCodeqlExecuteScanTestsUtils())
dir, _ := os.Getwd()
projectSettingsPath := filepath.Join(dir, "test.xml")
expectedCommand := fmt.Sprintf(" --settings=%s", projectSettingsPath)
expectedCommand := fmt.Sprintf(" \"--settings=%s\"", projectSettingsPath)
assert.Equal(t, expectedCommand, params)
})

Expand All @@ -73,7 +73,7 @@ func TestGetMavenSettings(t *testing.T) {
params := getMavenSettings(buildCmd, &config, newCodeqlExecuteScanTestsUtils())
dir, _ := os.Getwd()
globalSettingsPath := filepath.Join(dir, "global.xml")
expectedCommand := fmt.Sprintf(" --global-settings=%s", globalSettingsPath)
expectedCommand := fmt.Sprintf(" \"--global-settings=%s\"", globalSettingsPath)
assert.Equal(t, expectedCommand, params)
})

Expand All @@ -84,7 +84,7 @@ func TestGetMavenSettings(t *testing.T) {
dir, _ := os.Getwd()
globalSettingsPath := filepath.Join(dir, "global.xml")
projectSettingsPath := filepath.Join(dir, "test.xml")
expectedCommand := fmt.Sprintf(" --global-settings=%s --settings=%s", globalSettingsPath, projectSettingsPath)
expectedCommand := fmt.Sprintf(" \"--global-settings=%s\" \"--settings=%s\"", globalSettingsPath, projectSettingsPath)
assert.Equal(t, expectedCommand, params)
})

Expand All @@ -94,7 +94,7 @@ func TestGetMavenSettings(t *testing.T) {
params := getMavenSettings(buildCmd, &config, newCodeqlExecuteScanTestsUtils())
dir, _ := os.Getwd()
projectSettingsPath := filepath.Join(dir, ".pipeline/mavenProjectSettings.xml")
expectedCommand := fmt.Sprintf(" --settings=%s", projectSettingsPath)
expectedCommand := fmt.Sprintf(" \"--settings=%s\"", projectSettingsPath)
assert.Equal(t, expectedCommand, params)
})

Expand All @@ -104,7 +104,7 @@ func TestGetMavenSettings(t *testing.T) {
params := getMavenSettings(buildCmd, &config, newCodeqlExecuteScanTestsUtils())
dir, _ := os.Getwd()
projectSettingsPath := filepath.Join(dir, ".pipeline/mavenProjectSettings.xml")
expectedCommand := fmt.Sprintf(" --settings=%s", projectSettingsPath)
expectedCommand := fmt.Sprintf(" \"--settings=%s\"", projectSettingsPath)
assert.Equal(t, expectedCommand, params)
})

Expand All @@ -114,7 +114,7 @@ func TestGetMavenSettings(t *testing.T) {
params := getMavenSettings(buildCmd, &config, newCodeqlExecuteScanTestsUtils())
dir, _ := os.Getwd()
globalSettingsPath := filepath.Join(dir, ".pipeline/mavenGlobalSettings.xml")
expectedCommand := fmt.Sprintf(" --global-settings=%s", globalSettingsPath)
expectedCommand := fmt.Sprintf(" \"--global-settings=%s\"", globalSettingsPath)
assert.Equal(t, expectedCommand, params)
})

Expand All @@ -124,7 +124,7 @@ func TestGetMavenSettings(t *testing.T) {
params := getMavenSettings(buildCmd, &config, newCodeqlExecuteScanTestsUtils())
dir, _ := os.Getwd()
globalSettingsPath := filepath.Join(dir, ".pipeline/mavenGlobalSettings.xml")
expectedCommand := fmt.Sprintf(" --global-settings=%s", globalSettingsPath)
expectedCommand := fmt.Sprintf(" \"--global-settings=%s\"", globalSettingsPath)
assert.Equal(t, expectedCommand, params)
})

Expand All @@ -135,7 +135,7 @@ func TestGetMavenSettings(t *testing.T) {
dir, _ := os.Getwd()
globalSettingsPath := filepath.Join(dir, ".pipeline/mavenGlobalSettings.xml")
projectSettingsPath := filepath.Join(dir, ".pipeline/mavenProjectSettings.xml")
expectedCommand := fmt.Sprintf(" --global-settings=%s --settings=%s", globalSettingsPath, projectSettingsPath)
expectedCommand := fmt.Sprintf(" \"--global-settings=%s\" \"--settings=%s\"", globalSettingsPath, projectSettingsPath)
assert.Equal(t, expectedCommand, params)
})

Expand All @@ -146,7 +146,7 @@ func TestGetMavenSettings(t *testing.T) {
dir, _ := os.Getwd()
globalSettingsPath := filepath.Join(dir, ".pipeline/mavenGlobalSettings.xml")
projectSettingsPath := filepath.Join(dir, ".pipeline/mavenProjectSettings.xml")
expectedCommand := fmt.Sprintf(" --global-settings=%s --settings=%s", globalSettingsPath, projectSettingsPath)
expectedCommand := fmt.Sprintf(" \"--global-settings=%s\" \"--settings=%s\"", globalSettingsPath, projectSettingsPath)
assert.Equal(t, expectedCommand, params)
})

Expand All @@ -157,7 +157,7 @@ func TestGetMavenSettings(t *testing.T) {
dir, _ := os.Getwd()
globalSettingsPath := filepath.Join(dir, ".pipeline/mavenGlobalSettings.xml")
projectSettingsPath := filepath.Join(dir, "test.xml")
expectedCommand := fmt.Sprintf(" --global-settings=%s --settings=%s", globalSettingsPath, projectSettingsPath)
expectedCommand := fmt.Sprintf(" \"--global-settings=%s\" \"--settings=%s\"", globalSettingsPath, projectSettingsPath)
assert.Equal(t, expectedCommand, params)
})

Expand All @@ -168,7 +168,7 @@ func TestGetMavenSettings(t *testing.T) {
dir, _ := os.Getwd()
globalSettingsPath := filepath.Join(dir, ".pipeline/mavenGlobalSettings.xml")
projectSettingsPath := filepath.Join(dir, "test.xml")
expectedCommand := fmt.Sprintf(" --global-settings=%s --settings=%s", globalSettingsPath, projectSettingsPath)
expectedCommand := fmt.Sprintf(" \"--global-settings=%s\" \"--settings=%s\"", globalSettingsPath, projectSettingsPath)
assert.Equal(t, expectedCommand, params)
})

Expand All @@ -179,7 +179,7 @@ func TestGetMavenSettings(t *testing.T) {
dir, _ := os.Getwd()
globalSettingsPath := filepath.Join(dir, "global.xml")
projectSettingsPath := filepath.Join(dir, ".pipeline/mavenProjectSettings.xml")
expectedCommand := fmt.Sprintf(" --global-settings=%s --settings=%s", globalSettingsPath, projectSettingsPath)
expectedCommand := fmt.Sprintf(" \"--global-settings=%s\" \"--settings=%s\"", globalSettingsPath, projectSettingsPath)
assert.Equal(t, expectedCommand, params)
})

Expand All @@ -190,7 +190,7 @@ func TestGetMavenSettings(t *testing.T) {
dir, _ := os.Getwd()
globalSettingsPath := filepath.Join(dir, "global.xml")
projectSettingsPath := filepath.Join(dir, ".pipeline/mavenProjectSettings.xml")
expectedCommand := fmt.Sprintf(" --global-settings=%s --settings=%s", globalSettingsPath, projectSettingsPath)
expectedCommand := fmt.Sprintf(" \"--global-settings=%s\" \"--settings=%s\"", globalSettingsPath, projectSettingsPath)
assert.Equal(t, expectedCommand, params)
})
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func TestUpdateCmdFlag(t *testing.T) {
dir, _ := os.Getwd()
globalSettingsPath := filepath.Join(dir, "global.xml")
projectSettingsPath := filepath.Join(dir, "test.xml")
expectedCommand := fmt.Sprintf("mvn clean install --global-settings=%s --settings=%s", globalSettingsPath, projectSettingsPath)
expectedCommand := fmt.Sprintf("mvn clean install \"--global-settings=%s\" \"--settings=%s\"", globalSettingsPath, projectSettingsPath)
assert.Equal(t, expectedCommand, customFlags["--command"])
assert.Equal(t, "", customFlags["-c"])
})
Expand Down

0 comments on commit 085a8c0

Please sign in to comment.