Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codeqlExecuteScan): handle spaces in path to maven settings file #5037

Merged
merged 11 commits into from
Sep 12, 2024
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
Loading