From bef48c4ec554325b19948a626f8beadfe62bc965 Mon Sep 17 00:00:00 2001 From: "alexey.afanasiev" Date: Fri, 29 Nov 2024 09:59:24 +0100 Subject: [PATCH 1/2] :bug:QD-10360 Refactor passing options to installPlugins, add necessary options to common part with scan options (cherry picked from commit 0da11cc364138a48f20b0b0b384d000e6d3c0083) --- core/core_test.go | 2 +- core/ide.go | 2 +- core/properties.go | 65 +++++++++++++++++++++++++++++----------------- core/system.go | 1 - 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/core/core_test.go b/core/core_test.go index f3f2b6ac..359879fb 100644 --- a/core/core_test.go +++ b/core/core_test.go @@ -893,7 +893,7 @@ func Test_Properties(t *testing.T) { t.Fatal(err) } } - actual := GetProperties(opts, qConfig.Properties, qConfig.DotNet, []string{}) + actual := GetScanProperties(opts, qConfig.Properties, qConfig.DotNet, []string{}) assert.Equal(t, tc.expected, actual) }) } diff --git a/core/ide.go b/core/ide.go index 0fc92ab9..4eeab7e6 100644 --- a/core/ide.go +++ b/core/ide.go @@ -55,6 +55,7 @@ func getIdeExitCode(resultsDir string, c int) (res int) { } func runQodanaLocal(opts *QodanaOptions) (int, error) { + writeProperties(opts) args := getIdeRunCommand(opts) ideProcess, err := platform.RunCmdWithTimeout( "", @@ -307,7 +308,6 @@ func prepareLocalIdeSettings(opts *QodanaOptions) { opts.LogDirPath(), opts.ConfDirPath(), ) - writeProperties(opts) if platform.IsContainer() { err := syncIdeaCache(opts.CacheDir, opts.ProjectDir, false) diff --git a/core/properties.go b/core/properties.go index 1109f41a..726e26da 100644 --- a/core/properties.go +++ b/core/properties.go @@ -30,10 +30,6 @@ import ( func getPropertiesMap( prefix string, - systemDir string, - logDir string, - confDir string, - pluginsDir string, dotNet platform.DotNet, deviceIdSalt []string, plugins []string, @@ -44,10 +40,6 @@ func getPropertiesMap( "-Didea.headless.enable.statistics": strconv.FormatBool(cloud.Token.IsAllowedToSendFUS()), "-Didea.headless.statistics.device.id": deviceIdSalt[0], "-Didea.headless.statistics.salt": deviceIdSalt[1], - "-Didea.config.path": platform.QuoteIfSpace(confDir), - "-Didea.system.path": platform.QuoteIfSpace(systemDir), - "-Didea.plugins.path": platform.QuoteIfSpace(pluginsDir), - "-Didea.log.path": platform.QuoteIfSpace(logDir), "-Dqodana.automation.guid": platform.QuoteIfSpace(analysisId), "-XX:MaxRAMPercentage": "70", //only in docker? } @@ -82,19 +74,51 @@ func getPropertiesMap( return properties } -// GetProperties writes key=value `props` to file `f` having later key occurrence win -func GetProperties(opts *QodanaOptions, yamlProps map[string]string, dotNetOptions platform.DotNet, plugins []string) []string { +// Common part for installPlugins and qodana executuion +func GetCommonProperties(opts *QodanaOptions) []string { + systemDir := filepath.Join(opts.CacheDir, "idea", Prod.getVersionBranch()) + pluginsDir := filepath.Join(opts.CacheDir, "plugins", Prod.getVersionBranch()) lines := []string{ - fmt.Sprintf("-Xlog:gc*:%s", platform.QuoteIfSpace(filepath.Join(opts.LogDirPath(), "gc.log"))), - } - if opts.JvmDebugPort > 0 { - lines = append(lines, fmt.Sprintf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:%s", containerJvmDebugPort)) + fmt.Sprintf("-Didea.config.path=%s", platform.QuoteIfSpace(opts.ConfDirPath())), + fmt.Sprintf("-Didea.system.path=%s", platform.QuoteIfSpace(systemDir)), + fmt.Sprintf("-Didea.plugins.path=%s", platform.QuoteIfSpace(pluginsDir)), + fmt.Sprintf("-Didea.log.path=%s", platform.QuoteIfSpace(opts.LogDirPath())), } treatAsRelease := os.Getenv(platform.QodanaTreatAsRelease) if treatAsRelease == "true" { lines = append(lines, "-Deap.require.license=release") } + return lines +} + +func GetInstallPluginsProperties(opts *QodanaOptions) []string { + lines := GetCommonProperties(opts) + + lines = append(lines, + "-Didea.headless.enable.statistics=false", + "-Dqodana.application=true", + "-Dintellij.platform.load.app.info.from.resources=true", + fmt.Sprintf("-Dqodana.build.number=%s-%s", Prod.IDECode, Prod.Build), + ) + + sort.Strings(lines) + return lines +} + +// GetScanProperties writes key=value `props` to file `f` having later key occurrence win +func GetScanProperties(opts *QodanaOptions, yamlProps map[string]string, dotNetOptions platform.DotNet, plugins []string) []string { + lines := GetCommonProperties(opts) + + lines = append( + lines, + fmt.Sprintf("-Xlog:gc*:%s", platform.QuoteIfSpace(filepath.Join(opts.LogDirPath(), "gc.log"))), + ) + + if opts.JvmDebugPort > 0 { + lines = append(lines, fmt.Sprintf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:%s", containerJvmDebugPort)) + } + customPluginPathsValue := getCustomPluginPaths() if customPluginPathsValue != "" { lines = append(lines, fmt.Sprintf("-Dplugin.path=%s", customPluginPathsValue)) @@ -109,10 +133,6 @@ func GetProperties(opts *QodanaOptions, yamlProps map[string]string, dotNetOptio props := getPropertiesMap( Prod.parentPrefix(), - filepath.Join(opts.CacheDir, "idea", Prod.getVersionBranch()), - opts.LogDirPath(), - opts.ConfDirPath(), - filepath.Join(opts.CacheDir, "plugins", Prod.getVersionBranch()), dotNetOptions, platform.GetDeviceIdSalt(), plugins, @@ -160,7 +180,7 @@ func getCustomPluginPaths() string { // writeProperties writes the given key=value `props` to file `f` (sets the environment variable) func writeProperties(opts *QodanaOptions) { // opts.confDirPath(Prod.Version) opts.vmOptionsPath(Prod.Version) - properties := GetProperties(opts, opts.QdConfig.Properties, opts.QdConfig.DotNet, getPluginIds(opts.QdConfig.Plugins)) + properties := GetScanProperties(opts, opts.QdConfig.Properties, opts.QdConfig.DotNet, getPluginIds(opts.QdConfig.Plugins)) err := os.WriteFile(opts.vmOptionsPath(), []byte(strings.Join(properties, "\n")), 0o644) if err != nil { log.Fatal(err) @@ -172,11 +192,8 @@ func writeProperties(opts *QodanaOptions) { // opts.confDirPath(Prod.Version) o } func setInstallPluginsVmoptions(opts *QodanaOptions) { - vmOptions := []string{ - "-Dqodana.application=true", - "-Dintellij.platform.load.app.info.from.resources=true", - fmt.Sprintf("-Dqodana.build.number=%s-%s", Prod.IDECode, Prod.Build), - } + vmOptions := GetInstallPluginsProperties(opts) + log.Debugf("install plugins options:%s", vmOptions) err := os.WriteFile(opts.installPluginsVmOptionsPath(), []byte(strings.Join(vmOptions, "\n")), 0o644) if err != nil { log.Fatal(err) diff --git a/core/system.go b/core/system.go index b16cc58c..3db7fe7d 100644 --- a/core/system.go +++ b/core/system.go @@ -353,7 +353,6 @@ func runScopeScript(ctx context.Context, options *QodanaOptions, startHash strin platform.Bootstrap(configAtHash.Bootstrap, options.ProjectDir) installPlugins(options, configAtHash.Plugins) - writeProperties(options) exitCode := runQodana(ctx, options) if !(exitCode == 0 || exitCode == 255) { log.Errorf("Qodana analysis on %s exited with code %d. Aborting", hash, exitCode) From 5927bcb3b47f5468a620ce5b678ba800ab604685 Mon Sep 17 00:00:00 2001 From: "alexey.afanasiev" Date: Sat, 30 Nov 2024 23:30:34 +0100 Subject: [PATCH 2/2] :bug:QD-10419 Set up plugins once even in scoped script (cherry picked from commit 9fce6357f8eee1e19a5f70382e02a54192064496) --- core/system.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/system.go b/core/system.go index 3db7fe7d..996714c1 100644 --- a/core/system.go +++ b/core/system.go @@ -200,10 +200,11 @@ func RunAnalysis(ctx context.Context, options *QodanaOptions) int { scenario = runScenarioDefault options.ResetScanScenarioOptions() } + + installPlugins(options, options.QdConfig.Plugins) // this way of running needs to do bootstrap twice on different commits and will do it internally if scenario != runScenarioScoped && options.Ide != "" { platform.Bootstrap(options.QdConfig.Bootstrap, options.ProjectDir) - installPlugins(options, options.QdConfig.Plugins) } switch scenario { case runScenarioFullHistory: @@ -351,7 +352,6 @@ func runScopeScript(ctx context.Context, options *QodanaOptions, startHash strin configAtHash = options.QdConfig } platform.Bootstrap(configAtHash.Bootstrap, options.ProjectDir) - installPlugins(options, configAtHash.Plugins) exitCode := runQodana(ctx, options) if !(exitCode == 0 || exitCode == 255) {