Skip to content

Commit 7091687

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

File tree

3 files changed

+115
-18
lines changed

3 files changed

+115
-18
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/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
}

0 commit comments

Comments
 (0)