Skip to content

Commit

Permalink
🐛QD-10360 Refactor passing options to installPlugins, add necessary o…
Browse files Browse the repository at this point in the history
…ptions to common part with scan options
  • Loading branch information
avafanasiev committed Nov 29, 2024
1 parent c25983e commit 0da11cc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
2 changes: 1 addition & 1 deletion core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
2 changes: 1 addition & 1 deletion core/ide.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"",
Expand Down Expand Up @@ -307,7 +308,6 @@ func prepareLocalIdeSettings(opts *QodanaOptions) {
opts.LogDirPath(),
opts.ConfDirPath(),
)
writeProperties(opts)

if platform.IsContainer() {
err := syncIdeaCache(opts.CacheDir, opts.ProjectDir, false)
Expand Down
65 changes: 41 additions & 24 deletions core/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ import (

func getPropertiesMap(
prefix string,
systemDir string,
logDir string,
confDir string,
pluginsDir string,
dotNet platform.DotNet,
deviceIdSalt []string,
plugins []string,
Expand All @@ -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?
}
Expand Down Expand Up @@ -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))
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion core/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,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)
Expand Down

0 comments on commit 0da11cc

Please sign in to comment.