Skip to content

Commit 5d2ca51

Browse files
committed
[jb] enable vmoptions config in .gitpod.yml
1 parent a705517 commit 5d2ca51

File tree

8 files changed

+95
-13
lines changed

8 files changed

+95
-13
lines changed

components/gitpod-protocol/data/gitpod-schema.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@
287287
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
288288
}
289289
}
290+
},
291+
"vmoptions": {
292+
"type": "string",
293+
"description": "Adjust VM options for the remote IDE server, especially if you want to increase the '-Xmx' memory size when working with a larger project. See https://www.jetbrains.com/help/idea/tuning-the-ide.html#configure-jvm-options"
290294
}
291295
}
292296
},
@@ -317,6 +321,10 @@
317321
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
318322
}
319323
}
324+
},
325+
"vmoptions": {
326+
"type": "string",
327+
"description": "Adjust VM options for the remote IDE server, especially if you want to increase the '-Xmx' memory size when working with a larger project. See https://www.jetbrains.com/help/idea/tuning-the-ide.html#configure-jvm-options"
320328
}
321329
}
322330
},
@@ -347,6 +355,10 @@
347355
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
348356
}
349357
}
358+
},
359+
"vmoptions": {
360+
"type": "string",
361+
"description": "Adjust VM options for the remote IDE server, especially if you want to increase the '-Xmx' memory size when working with a larger project. See https://www.jetbrains.com/help/idea/tuning-the-ide.html#configure-jvm-options"
350362
}
351363
}
352364
},
@@ -377,6 +389,10 @@
377389
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
378390
}
379391
}
392+
},
393+
"vmoptions": {
394+
"type": "string",
395+
"description": "Adjust VM options for the remote IDE server, especially if you want to increase the '-Xmx' memory size when working with a larger project. See https://www.jetbrains.com/help/idea/tuning-the-ide.html#configure-jvm-options"
380396
}
381397
}
382398
}

components/gitpod-protocol/go/gitpod-config-types.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/gitpod-protocol/src/protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ export interface JetBrainsConfig {
640640
}
641641
export interface JetBrainsProductConfig {
642642
prebuilds?: JetBrainsPrebuilds;
643+
vmoptions?: string;
643644
}
644645
export interface JetBrainsPrebuilds {
645646
version?: "stable" | "latest" | "both";

components/ide/jetbrains/image/status/go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ go 1.18
55
require (
66
github.com/gitpod-io/gitpod/supervisor/api v0.0.0-00010101000000-000000000000
77
github.com/google/go-cmp v0.5.7
8+
github.com/stretchr/testify v1.7.0
89
)
910

1011
require (
12+
github.com/davecgh/go-spew v1.1.1 // indirect
1113
github.com/golang/mock v1.6.0 // indirect
1214
github.com/gorilla/websocket v1.5.0 // indirect
15+
github.com/pmezard/go-difflib v1.0.0 // indirect
1316
github.com/sirupsen/logrus v1.8.1 // indirect
1417
github.com/sourcegraph/jsonrpc2 v0.0.0-20200429184054-15c2290dcb37 // indirect
18+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
1519
)
1620

1721
require (

components/ide/jetbrains/image/status/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
428428
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
429429
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
430430
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
431+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
431432
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
432433
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
433434
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

components/ide/jetbrains/image/status/main.go

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ func main() {
7676
}
7777
log.WithField("cost", time.Now().Local().Sub(startTime).Milliseconds()).Info("content available")
7878

79+
repoRoot := wsInfo.GetCheckoutLocation()
7980
version_2022_1, _ := version.NewVersion("2022.1")
8081
if version_2022_1.LessThanOrEqual(backendVersion) {
81-
err = installPlugins(wsInfo, alias)
82+
err = installPlugins(repoRoot, alias)
8283
installPluginsCost := time.Now().Local().Sub(startTime).Milliseconds()
8384
if err != nil {
8485
log.WithError(err).WithField("cost", installPluginsCost).Error("installing repo plugins: done")
@@ -87,7 +88,7 @@ func main() {
8788
}
8889
}
8990

90-
err = configureVMOptions(alias)
91+
err = configureVMOptions(repoRoot, alias)
9192
if err != nil {
9293
log.WithError(err).Error("failed to configure vmoptions")
9394
}
@@ -307,7 +308,7 @@ func handleSignal(projectPath string) {
307308
log.Info("asked IDE to terminate")
308309
}
309310

310-
func configureVMOptions(alias string) error {
311+
func configureVMOptions(repoRoot string, alias string) error {
311312
idePrefix := alias
312313
if alias == "intellij" {
313314
idePrefix = "idea"
@@ -318,7 +319,7 @@ func configureVMOptions(alias string) error {
318319
if err != nil {
319320
return err
320321
}
321-
newContent := updateVMOptions(alias, string(content))
322+
newContent := updateVMOptions(repoRoot, alias, string(content))
322323
return ioutil.WriteFile(path, []byte(newContent), 0)
323324
}
324325

@@ -340,7 +341,7 @@ func deduplicateVMOption(oldLines []string, newLines []string, predicate func(l,
340341
return result
341342
}
342343

343-
func updateVMOptions(alias string, content string) string {
344+
func updateVMOptions(repoRoot string, alias string, content string) string {
344345
// inspired by how intellij platform merge the VMOptions
345346
// https://github.com/JetBrains/intellij-community/blob/master/platform/platform-impl/src/com/intellij/openapi/application/ConfigImportHelper.java#L1115
346347
filterFunc := func(l, r string) bool {
@@ -358,12 +359,25 @@ func updateVMOptions(alias string, content string) string {
358359
gitpodVMOptions := []string{"-Dgtw.disable.exit.dialog=true"}
359360
vmoptions := deduplicateVMOption(ideaVMOptionsLines, gitpodVMOptions, filterFunc)
360361

361-
// user-defined vmoptions
362+
// user-defined vmoptions (EnvVar)
362363
userVMOptionsVar := os.Getenv(strings.ToUpper(alias) + "_VMOPTIONS")
363364
userVMOptions := strings.Fields(userVMOptionsVar)
364365
if len(userVMOptions) > 0 {
365366
vmoptions = deduplicateVMOption(vmoptions, userVMOptions, filterFunc)
366367
}
368+
369+
// user-defined vmoptions (.gitpod.yml)
370+
gitpodConfig, err := parseGitpodConfig(repoRoot)
371+
if gitpodConfig != nil && err == nil {
372+
productConfig := getProductConfig(gitpodConfig, alias)
373+
if productConfig != nil {
374+
userVMOptions = strings.Fields(productConfig.VMOptions)
375+
if len(userVMOptions) > 0 {
376+
vmoptions = deduplicateVMOption(vmoptions, userVMOptions, filterFunc)
377+
}
378+
}
379+
}
380+
367381
// vmoptions file should end with a newline
368382
return strings.Join(vmoptions, "\n") + "\n"
369383
}
@@ -410,8 +424,8 @@ func resolveBackendVersion() (*version.Version, error) {
410424
return version.NewVersion(info.Version)
411425
}
412426

413-
func installPlugins(wsInfo *supervisor.WorkspaceInfoResponse, alias string) error {
414-
plugins, err := getPlugins(wsInfo.GetCheckoutLocation(), alias)
427+
func installPlugins(repoRoot string, alias string) error {
428+
plugins, err := getPlugins(repoRoot, alias)
415429
if err != nil {
416430
return err
417431
}
@@ -433,7 +447,7 @@ func installPlugins(wsInfo *supervisor.WorkspaceInfoResponse, alias string) erro
433447

434448
var args []string
435449
args = append(args, "installPlugins")
436-
args = append(args, wsInfo.GetCheckoutLocation())
450+
args = append(args, repoRoot)
437451
args = append(args, plugins...)
438452
cmd := remoteDevServerCmd(args)
439453
cmd.Stdout = io.MultiWriter(w, os.Stdout)
@@ -458,7 +472,7 @@ func installPlugins(wsInfo *supervisor.WorkspaceInfoResponse, alias string) erro
458472
return nil
459473
}
460474

461-
func getPlugins(repoRoot string, alias string) ([]string, error) {
475+
func parseGitpodConfig(repoRoot string) (*gitpod.GitpodConfig, error) {
462476
if repoRoot == "" {
463477
return nil, errors.New("repoRoot is empty")
464478
}
@@ -474,11 +488,18 @@ func getPlugins(repoRoot string, alias string) ([]string, error) {
474488
if err = yaml.Unmarshal(data, &config); err != nil {
475489
return nil, errors.New("unmarshal .gitpod.yml file failed" + err.Error())
476490
}
491+
return config, nil
492+
}
477493

494+
func getPlugins(repoRoot string, alias string) ([]string, error) {
495+
var plugins []string
496+
config, err := parseGitpodConfig(repoRoot)
497+
if err != nil {
498+
return nil, err
499+
}
478500
if config == nil || config.JetBrains == nil {
479501
return nil, nil
480502
}
481-
var plugins []string
482503
if config.JetBrains.Plugins != nil {
483504
plugins = append(plugins, config.JetBrains.Plugins...)
484505
}

components/ide/jetbrains/image/status/main_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
protocol "github.com/gitpod-io/gitpod/gitpod-protocol"
1212
"github.com/google/go-cmp/cmp"
1313
"github.com/google/go-cmp/cmp/cmpopts"
14+
"github.com/stretchr/testify/assert"
1415
)
1516

1617
func TestGetProductConfig(t *testing.T) {
@@ -26,6 +27,14 @@ func TestGetProductConfig(t *testing.T) {
2627
}
2728
}
2829

30+
func TestParseGitpodConfig(t *testing.T) {
31+
gitpodConfig, _ := parseGitpodConfig("testdata")
32+
assert.Equal(t, 1, len(gitpodConfig.JetBrains.IntelliJ.Plugins))
33+
assert.Equal(t, "both", gitpodConfig.JetBrains.IntelliJ.Prebuilds.Version)
34+
assert.Equal(t, "-Xmx3g", gitpodConfig.JetBrains.IntelliJ.VMOptions)
35+
assert.Equal(t, "-Xmx4096m -XX:MaxRAMPercentage=75", gitpodConfig.JetBrains.GoLand.VMOptions)
36+
}
37+
2938
func TestUpdateVMOptions(t *testing.T) {
3039
tests := []struct {
3140
Desc string
@@ -49,7 +58,7 @@ func TestUpdateVMOptions(t *testing.T) {
4958
lessFunc := func(a, b string) bool { return a < b }
5059

5160
t.Run(test.Desc, func(t *testing.T) {
52-
actual := updateVMOptions(test.Alias, test.Src)
61+
actual := updateVMOptions("", test.Alias, test.Src)
5362
if diff := cmp.Diff(strings.Fields(test.Expectation), strings.Fields(actual), cmpopts.SortSlices(lessFunc)); diff != "" {
5463
t.Errorf("unexpected output (-want +got):\n%s", diff)
5564
}
@@ -58,7 +67,7 @@ func TestUpdateVMOptions(t *testing.T) {
5867
t.Run("updateVMOptions multiple time should be stable", func(t *testing.T) {
5968
actual := test.Src
6069
for i := 0; i < 5; i++ {
61-
actual = updateVMOptions(test.Alias, actual)
70+
actual = updateVMOptions("", test.Alias, actual)
6271
if diff := cmp.Diff(strings.Fields(test.Expectation), strings.Fields(actual), cmpopts.SortSlices(lessFunc)); diff != "" {
6372
t.Errorf("unexpected output (-want +got):\n%s", diff)
6473
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# see https://github.com/gitpod-io/spring-petclinic/blob/master/.gitpod.yml
2+
tasks:
3+
- init: ./mvnw package -DskipTests
4+
command: java -jar target/*.jar
5+
name: Run PetClinic app
6+
7+
# exposed ports
8+
ports:
9+
- port: 8080
10+
onOpen: open-preview
11+
12+
vscode:
13+
extensions:
14+
- redhat.java
15+
- vscjava.vscode-java-debug
16+
- vscjava.vscode-java-test
17+
- pivotal.vscode-spring-boot
18+
19+
jetbrains:
20+
intellij:
21+
plugins:
22+
- com.haulmont.jpab
23+
prebuilds:
24+
version: both
25+
vmoptions: "-Xmx3g"
26+
goland:
27+
vmoptions: "-Xmx4096m -XX:MaxRAMPercentage=75"

0 commit comments

Comments
 (0)