Skip to content

Commit 29d364b

Browse files
committed
[GP CLI]
1 parent 7b83abe commit 29d364b

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) 2024 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 cmd
6+
7+
import (
8+
"os"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
const gradleSyncLockFile = "/tmp/gitpod-gradle.lock"
14+
15+
var jetbrainsGradlePauseCmd = &cobra.Command{
16+
Use: "pause",
17+
Short: "Pause Gradle Sync in JetBrains IDEs",
18+
Long: `Pause JetBrains IDE gradle sync to prevent performance issues on Gitpod workspace startup when there's no Prebuilds ready.
19+
20+
This command is typically used to prevent concurrent Gradle syncs between:
21+
- Manual gradle initialization in Gitpod init tasks
22+
- JetBrains Gateway/IDEA's automatic Gradle sync on project open
23+
24+
Typical usage in your .gitpod.yml:
25+
26+
tasks:
27+
- init: |
28+
ide jetbrains gradle pause # Prevent IDEA's gradle sync
29+
...
30+
./gradlew <init_service> # Run your initialization tasks
31+
ide jetbrains gradle resume # Enable
32+
command: ./gradlew <dev_service>
33+
34+
If you have two init tasks want to pause Gradle Sync:
35+
36+
tasks:
37+
- name: Task 1
38+
init: |
39+
ide jetbrains gradle pause # Prevent IDEA's gradle sync
40+
./gradlew <init_service>
41+
gp sync-await gradle-init-1
42+
ide jetbrains gradle resume # Enable
43+
- name: Task 2
44+
init: |
45+
./gradlew <init_service>
46+
gp sync-done gradle-init-1
47+
`,
48+
RunE: func(cmd *cobra.Command, args []string) error {
49+
err := os.WriteFile(gradleSyncLockFile, []byte{}, 0644)
50+
if err != nil && os.IsExist(err) {
51+
return nil
52+
}
53+
return err
54+
},
55+
}
56+
57+
func init() {
58+
jetbrainsGradleCmd.AddCommand(jetbrainsGradlePauseCmd)
59+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2024 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 cmd
6+
7+
import (
8+
"os"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var jetbrainsGradleResumeCmd = &cobra.Command{
14+
Use: "resume",
15+
Short: "Resume paused Gradle Sync in JetBrains IDEs",
16+
RunE: func(cmd *cobra.Command, args []string) error {
17+
err := os.Remove(gradleSyncLockFile)
18+
if err != nil && os.IsNotExist(err) {
19+
return nil
20+
}
21+
return err
22+
},
23+
}
24+
25+
func init() {
26+
jetbrainsGradleCmd.AddCommand(jetbrainsGradleResumeCmd)
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2024 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 cmd
6+
7+
import (
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var jetbrainsGradleCmd = &cobra.Command{
12+
Use: "gradle",
13+
Short: "Interact with JetBrains Gradle services.",
14+
}
15+
16+
func init() {
17+
jetbrainsCmd.AddCommand(jetbrainsGradleCmd)
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2024 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 cmd
6+
7+
import (
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var jetbrainsCmd = &cobra.Command{
12+
Use: "jetbrains",
13+
Aliases: []string{"jb"},
14+
Short: "Interact with JetBrains editor.",
15+
}
16+
17+
func init() {
18+
rootCmd.AddCommand(jetbrainsCmd)
19+
}

0 commit comments

Comments
 (0)