Skip to content

Commit c1d7453

Browse files
committed
[jb] allow to specify plugins per a product
1 parent cbda0c1 commit c1d7453

File tree

6 files changed

+146
-20
lines changed

6 files changed

+146
-20
lines changed

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,66 @@
255255
"properties": {
256256
"plugins": {
257257
"type": "array",
258-
"description": "List of plugins which should be installed for users of this workspace. From the JetBrains Marketplace page, find a page of the required plugin, select 'Versions' tab, click any version to copy pluginId (short name such as org.rust.lang) of the plugin you want to install.",
258+
"description": "List of plugins which should be installed for all JetBrains product for users of this workspace. From the JetBrains Marketplace page, find a page of the required plugin, select 'Versions' tab, click any version to copy pluginId (short name such as org.rust.lang) of the plugin you want to install.",
259259
"items": {
260260
"type": "string"
261261
}
262+
},
263+
"intellij": {
264+
"type": "object",
265+
"description": "Configure IntelliJ integration",
266+
"additionalProperties": false,
267+
"properties": {
268+
"plugins": {
269+
"type": "array",
270+
"description": "List of plugins which should be installed for users of this workspace. From the JetBrains Marketplace page, find a page of the required plugin, select 'Versions' tab, click any version to copy pluginId (short name such as org.rust.lang) of the plugin you want to install.",
271+
"items": {
272+
"type": "string"
273+
}
274+
}
275+
}
276+
},
277+
"goland": {
278+
"type": "object",
279+
"description": "Configure GoLand integration",
280+
"additionalProperties": false,
281+
"properties": {
282+
"plugins": {
283+
"type": "array",
284+
"description": "List of plugins which should be installed for users of this workspace. From the JetBrains Marketplace page, find a page of the required plugin, select 'Versions' tab, click any version to copy pluginId (short name such as org.rust.lang) of the plugin you want to install.",
285+
"items": {
286+
"type": "string"
287+
}
288+
}
289+
}
290+
},
291+
"pycharm": {
292+
"type": "object",
293+
"description": "Configure PyCharm integration",
294+
"additionalProperties": false,
295+
"properties": {
296+
"plugins": {
297+
"type": "array",
298+
"description": "List of plugins which should be installed for users of this workspace. From the JetBrains Marketplace page, find a page of the required plugin, select 'Versions' tab, click any version to copy pluginId (short name such as org.rust.lang) of the plugin you want to install.",
299+
"items": {
300+
"type": "string"
301+
}
302+
}
303+
}
304+
},
305+
"phpstorm": {
306+
"type": "object",
307+
"description": "Configure PhpStorm integration",
308+
"additionalProperties": false,
309+
"properties": {
310+
"plugins": {
311+
"type": "array",
312+
"description": "List of plugins which should be installed for users of this workspace. From the JetBrains Marketplace page, find a page of the required plugin, select 'Versions' tab, click any version to copy pluginId (short name such as org.rust.lang) of the plugin you want to install.",
313+
"items": {
314+
"type": "string"
315+
}
316+
}
317+
}
262318
}
263319
}
264320
},

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

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

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ module github.com/gitpod-io/gitpod/jetbrains/status
22

33
go 1.17
44

5-
require github.com/gitpod-io/gitpod/supervisor/api v0.0.0-00010101000000-000000000000
5+
require (
6+
github.com/gitpod-io/gitpod/supervisor/api v0.0.0-00010101000000-000000000000
7+
github.com/google/go-cmp v0.5.6
8+
)
69

710
require (
811
github.com/golang/mock v1.6.0 // indirect

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ github.com/sourcegraph/jsonrpc2 v0.0.0-20200429184054-15c2290dcb37/go.mod h1:Zaf
144144
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
145145
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
146146
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
147-
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
148147
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
148+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
149149
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
150150
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
151151
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -420,6 +420,7 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
420420
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
421421
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
422422
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
423+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
423424
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
424425
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
425426
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

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

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import (
1717
"os"
1818
"os/exec"
1919
"path/filepath"
20+
"reflect"
2021
"regexp"
22+
"strings"
2123
"time"
2224

2325
"github.com/hashicorp/go-version"
@@ -51,7 +53,7 @@ func main() {
5153
log.Fatalf("Usage: %s <port> <kind> [<link label>]\n", os.Args[0])
5254
}
5355
port := os.Args[1]
54-
kind := os.Args[2]
56+
alias := os.Args[2]
5557
label := "Open JetBrains IDE"
5658
if len(os.Args) > 3 {
5759
label = os.Args[3]
@@ -73,7 +75,7 @@ func main() {
7375

7476
version_2022_1, _ := version.NewVersion("2022.1")
7577
if version_2022_1.LessThanOrEqual(backendVersion) {
76-
err = installPlugins(wsInfo)
78+
err = installPlugins(wsInfo, alias)
7779
installPluginsCost := time.Now().Local().Sub(startTime).Milliseconds()
7880
if err != nil {
7981
log.WithError(err).WithField("cost", installPluginsCost).Error("installing repo plugins: done")
@@ -125,7 +127,7 @@ func main() {
125127
response["link"] = gatewayLink
126128
response["label"] = label
127129
response["clientID"] = "jetbrains-gateway"
128-
response["kind"] = kind
130+
response["kind"] = alias
129131
w.Header().Set("Content-Type", "application/json")
130132
_ = json.NewEncoder(w).Encode(response)
131133
})
@@ -294,8 +296,8 @@ func resolveBackendVersion() (*version.Version, error) {
294296
return version.NewVersion(info.Version)
295297
}
296298

297-
func installPlugins(wsInfo *supervisor.WorkspaceInfoResponse) error {
298-
plugins, err := getPlugins(wsInfo.GetCheckoutLocation())
299+
func installPlugins(wsInfo *supervisor.WorkspaceInfoResponse, alias string) error {
300+
plugins, err := getPlugins(wsInfo.GetCheckoutLocation(), alias)
299301
if err != nil {
300302
return err
301303
}
@@ -342,29 +344,49 @@ func installPlugins(wsInfo *supervisor.WorkspaceInfoResponse) error {
342344
return nil
343345
}
344346

345-
func getPlugins(repoRoot string) (plugins []string, err error) {
347+
func getPlugins(repoRoot string, alias string) ([]string, error) {
346348
if repoRoot == "" {
347-
err = errors.New("repoRoot is empty")
348-
return
349+
return nil, errors.New("repoRoot is empty")
349350
}
350351
data, err := os.ReadFile(filepath.Join(repoRoot, ".gitpod.yml"))
351352
if err != nil {
352353
// .gitpod.yml not exist is ok
353354
if errors.Is(err, os.ErrNotExist) {
354-
err = nil
355-
return
355+
return nil, nil
356356
}
357-
err = errors.New("read .gitpod.yml file failed: " + err.Error())
358-
return
357+
return nil, errors.New("read .gitpod.yml file failed: " + err.Error())
359358
}
360359
var config *gitpod.GitpodConfig
361360
if err = yaml.Unmarshal(data, &config); err != nil {
362-
err = errors.New("unmarshal .gitpod.yml file failed" + err.Error())
363-
return
361+
return nil, errors.New("unmarshal .gitpod.yml file failed" + err.Error())
364362
}
363+
365364
if config == nil || config.JetBrains == nil {
366-
err = errors.New("config.vscode field not exists")
367-
return
365+
return nil, nil
366+
}
367+
var plugins []string
368+
if config.JetBrains.Plugins != nil {
369+
plugins = append(plugins, config.JetBrains.Plugins...)
370+
}
371+
productConfig := getProductConfig(config, alias)
372+
if productConfig != nil && productConfig.Plugins != nil {
373+
plugins = append(plugins, productConfig.Plugins...)
374+
}
375+
return plugins, nil
376+
}
377+
378+
func getProductConfig(config *gitpod.GitpodConfig, alias string) *gitpod.JetBrainsProduct {
379+
defer func() {
380+
if err := recover(); err != nil {
381+
log.WithField("error", err).WithField("alias", alias).Error("failed to extract JB product config")
382+
}
383+
}()
384+
v := reflect.ValueOf(*config.JetBrains).FieldByNameFunc(func(s string) bool {
385+
return strings.ToLower(s) == alias
386+
}).Interface()
387+
productConfig, ok := v.(*gitpod.JetBrainsProduct)
388+
if !ok {
389+
return nil
368390
}
369-
return config.JetBrains.Plugins, nil
391+
return productConfig
370392
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package main
6+
7+
import (
8+
"testing"
9+
10+
protocol "github.com/gitpod-io/gitpod/gitpod-protocol"
11+
"github.com/google/go-cmp/cmp"
12+
)
13+
14+
func TestGetProductConfig(t *testing.T) {
15+
expectation := &protocol.JetBrainsProduct{}
16+
actual := getProductConfig(&protocol.GitpodConfig{
17+
JetBrains: &protocol.JetBrains{
18+
IntelliJ: expectation,
19+
},
20+
}, "intellij")
21+
22+
if diff := cmp.Diff(expectation, actual); diff != "" {
23+
t.Errorf("unexpected output (-want +got):\n%s", diff)
24+
}
25+
}

0 commit comments

Comments
 (0)