From b2bb2b531cc54e1df19167da885905c4b76647b7 Mon Sep 17 00:00:00 2001 From: Daria Kuznetsova Date: Wed, 4 Sep 2024 12:49:37 +0200 Subject: [PATCH 1/8] added quotes for mvn settings path --- cmd/codeqlExecuteScan.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/codeqlExecuteScan.go b/cmd/codeqlExecuteScan.go index 88b833ab78..166cada7be 100644 --- a/cmd/codeqlExecuteScan.go +++ b/cmd/codeqlExecuteScan.go @@ -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 From a72b90ffef99a49c621018c37828e6363b526d74 Mon Sep 17 00:00:00 2001 From: Daria Kuznetsova Date: Wed, 4 Sep 2024 13:03:19 +0200 Subject: [PATCH 2/8] added logs --- cmd/codeqlExecuteScan.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/codeqlExecuteScan.go b/cmd/codeqlExecuteScan.go index 166cada7be..47aeb4525a 100644 --- a/cmd/codeqlExecuteScan.go +++ b/cmd/codeqlExecuteScan.go @@ -334,6 +334,7 @@ func prepareCmdForDatabaseCreate(customFlags map[string]string, config *codeqlEx buildCmd := config.BuildCommand buildCmd = buildCmd + getMavenSettings(buildCmd, config, utils) cmd = append(cmd, "--command="+buildCmd) + log.Entry().Infof("cmd after appending mvn settings: %v", cmd) } if codeql.IsFlagSetByUser(customFlags, []string{"--command", "-c"}) { @@ -341,6 +342,8 @@ func prepareCmdForDatabaseCreate(customFlags map[string]string, config *codeqlEx } cmd = codeql.AppendCustomFlags(cmd, customFlags) + log.Entry().Infof("cmd after appending custom flags: %v", cmd) + return cmd, nil } @@ -481,8 +484,10 @@ func getMavenSettings(buildCmd string, config *codeqlExecuteScanOptions, utils c log.Entry().Error("failed to download and get maven parameters: ", err) return params } + log.Entry().Infof("params: %s, mvnParams: %v", params, mvnParams) 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]) + log.Entry().Infof("params: %s", params) } } return params @@ -497,5 +502,6 @@ func updateCmdFlag(config *codeqlExecuteScanOptions, customFlags map[string]stri } buildCmd += getMavenSettings(buildCmd, config, utils) customFlags["--command"] = buildCmd + log.Entry().Infof("customFlags[--command]: %s", customFlags["--command"]) delete(customFlags, "-c") } From 938a81b2428f38e5aed457f70803f1b84edebf07 Mon Sep 17 00:00:00 2001 From: Daria Kuznetsova Date: Wed, 4 Sep 2024 13:15:32 +0200 Subject: [PATCH 3/8] removed logs, added excape symbol for spaces --- cmd/codeqlExecuteScan.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cmd/codeqlExecuteScan.go b/cmd/codeqlExecuteScan.go index 47aeb4525a..d72bd4ca3f 100644 --- a/cmd/codeqlExecuteScan.go +++ b/cmd/codeqlExecuteScan.go @@ -334,7 +334,6 @@ func prepareCmdForDatabaseCreate(customFlags map[string]string, config *codeqlEx buildCmd := config.BuildCommand buildCmd = buildCmd + getMavenSettings(buildCmd, config, utils) cmd = append(cmd, "--command="+buildCmd) - log.Entry().Infof("cmd after appending mvn settings: %v", cmd) } if codeql.IsFlagSetByUser(customFlags, []string{"--command", "-c"}) { @@ -342,8 +341,6 @@ func prepareCmdForDatabaseCreate(customFlags map[string]string, config *codeqlEx } cmd = codeql.AppendCustomFlags(cmd, customFlags) - log.Entry().Infof("cmd after appending custom flags: %v", cmd) - return cmd, nil } @@ -484,10 +481,9 @@ func getMavenSettings(buildCmd string, config *codeqlExecuteScanOptions, utils c log.Entry().Error("failed to download and get maven parameters: ", err) return params } - log.Entry().Infof("params: %s, mvnParams: %v", params, mvnParams) for i := 1; i < len(mvnParams); i += 2 { - params = fmt.Sprintf("%s %s=%s", params, mvnParams[i-1], mvnParams[i]) - log.Entry().Infof("params: %s", params) + mvnParam := strings.ReplaceAll(mvnParams[i], " ", "\\ ") + params = fmt.Sprintf("%s %s=%s", params, mvnParams[i-1], mvnParam) } } return params From 9b2aa1210d176007b14c21e207599689fc6038f2 Mon Sep 17 00:00:00 2001 From: Daria Kuznetsova Date: Wed, 4 Sep 2024 13:29:20 +0200 Subject: [PATCH 4/8] set quotes --- cmd/codeqlExecuteScan.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/codeqlExecuteScan.go b/cmd/codeqlExecuteScan.go index d72bd4ca3f..1de88ffe4e 100644 --- a/cmd/codeqlExecuteScan.go +++ b/cmd/codeqlExecuteScan.go @@ -483,7 +483,7 @@ func getMavenSettings(buildCmd string, config *codeqlExecuteScanOptions, utils c } for i := 1; i < len(mvnParams); i += 2 { mvnParam := strings.ReplaceAll(mvnParams[i], " ", "\\ ") - params = fmt.Sprintf("%s %s=%s", params, mvnParams[i-1], mvnParam) + params = fmt.Sprintf("%s %s='%s'", params, mvnParams[i-1], mvnParam) } } return params From 472ba1f00b4b166c8c084ce704d692d2c487b3f5 Mon Sep 17 00:00:00 2001 From: Daria Kuznetsova Date: Wed, 4 Sep 2024 13:43:10 +0200 Subject: [PATCH 5/8] removed replacing --- cmd/codeqlExecuteScan.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/codeqlExecuteScan.go b/cmd/codeqlExecuteScan.go index 1de88ffe4e..9ab51c8f3c 100644 --- a/cmd/codeqlExecuteScan.go +++ b/cmd/codeqlExecuteScan.go @@ -482,8 +482,8 @@ func getMavenSettings(buildCmd string, config *codeqlExecuteScanOptions, utils c return params } for i := 1; i < len(mvnParams); i += 2 { - mvnParam := strings.ReplaceAll(mvnParams[i], " ", "\\ ") - params = fmt.Sprintf("%s %s='%s'", params, mvnParams[i-1], mvnParam) + //mvnParam := strings.ReplaceAll(mvnParams[i], " ", "\\ ") + params = fmt.Sprintf("%s %s='%s'", params, mvnParams[i-1], mvnParams[i]) } } return params From c42d3c5ea819606ce4eb28966d12a633d11a4a8a Mon Sep 17 00:00:00 2001 From: Daria Kuznetsova Date: Wed, 4 Sep 2024 13:56:37 +0200 Subject: [PATCH 6/8] changed quotes --- cmd/codeqlExecuteScan.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/codeqlExecuteScan.go b/cmd/codeqlExecuteScan.go index 9ab51c8f3c..ec878710c8 100644 --- a/cmd/codeqlExecuteScan.go +++ b/cmd/codeqlExecuteScan.go @@ -483,7 +483,7 @@ func getMavenSettings(buildCmd string, config *codeqlExecuteScanOptions, utils c } for i := 1; i < len(mvnParams); i += 2 { //mvnParam := strings.ReplaceAll(mvnParams[i], " ", "\\ ") - 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 From d3b0b63b36ce8475149f92a153064d4e4c43dc52 Mon Sep 17 00:00:00 2001 From: Daria Kuznetsova Date: Wed, 4 Sep 2024 14:18:04 +0200 Subject: [PATCH 7/8] fixed tests --- cmd/codeqlExecuteScan.go | 1 - cmd/codeqlExecuteScan_test.go | 28 ++++++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cmd/codeqlExecuteScan.go b/cmd/codeqlExecuteScan.go index ec878710c8..062081acd0 100644 --- a/cmd/codeqlExecuteScan.go +++ b/cmd/codeqlExecuteScan.go @@ -482,7 +482,6 @@ func getMavenSettings(buildCmd string, config *codeqlExecuteScanOptions, utils c return params } for i := 1; i < len(mvnParams); i += 2 { - //mvnParam := strings.ReplaceAll(mvnParams[i], " ", "\\ ") params = fmt.Sprintf("%s \"%s=%s\"", params, mvnParams[i-1], mvnParams[i]) } } diff --git a/cmd/codeqlExecuteScan_test.go b/cmd/codeqlExecuteScan_test.go index 4f8580eba4..959d3c9c7c 100644 --- a/cmd/codeqlExecuteScan_test.go +++ b/cmd/codeqlExecuteScan_test.go @@ -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) }) @@ -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) }) @@ -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) }) @@ -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) }) @@ -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) }) @@ -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) }) @@ -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) }) @@ -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) }) @@ -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) }) @@ -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) }) @@ -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) }) @@ -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) }) @@ -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) }) } @@ -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"]) }) From cfa9d36b46846c19e049a126a76e7dbf659bd8dd Mon Sep 17 00:00:00 2001 From: Daria Kuznetsova Date: Wed, 4 Sep 2024 14:18:49 +0200 Subject: [PATCH 8/8] removed extra log --- cmd/codeqlExecuteScan.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/codeqlExecuteScan.go b/cmd/codeqlExecuteScan.go index 062081acd0..fe66e8dc31 100644 --- a/cmd/codeqlExecuteScan.go +++ b/cmd/codeqlExecuteScan.go @@ -497,6 +497,5 @@ func updateCmdFlag(config *codeqlExecuteScanOptions, customFlags map[string]stri } buildCmd += getMavenSettings(buildCmd, config, utils) customFlags["--command"] = buildCmd - log.Entry().Infof("customFlags[--command]: %s", customFlags["--command"]) delete(customFlags, "-c") }