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

Avafanasev/qd 10360 qd 10419 #484

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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 @@
"-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 @@
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

Check notice on line 77 in core/properties.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetCommonProperties ...' (with an optional leading article)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather follow advice from linter here and adjust the comment

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 @@

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 @@

// 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 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
5 changes: 2 additions & 3 deletions core/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -351,9 +352,7 @@ func runScopeScript(ctx context.Context, options *QodanaOptions, startHash strin
configAtHash = options.QdConfig
}
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
Loading