Skip to content

Commit d17ce2c

Browse files
committed
Pause gradle sync
1 parent fe0428e commit d17ce2c

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

components/ide/jetbrains/backend-plugin/BUILD.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ packages:
151151
- NO_VERIFY_JB_PLUGIN=true
152152
config:
153153
commands:
154+
- ["rm", "-rf", "src/main/kotlin/io/gitpod/jetbrains/remote/listeners/GradleSyncListener.kt"]
154155
- ["mv", "build.gradle-stable.kts", "build.gradle.kts"]
155156
- ["./build.sh", "${__git_commit}"]
156157
- name: plugin-latest-rider
@@ -182,6 +183,7 @@ packages:
182183
- SDKMAN_DIR=/home/gitpod/.sdkman
183184
config:
184185
commands:
186+
- ["rm", "-rf", "src/main/kotlin/io/gitpod/jetbrains/remote/listeners/GradleSyncListener.kt"]
185187
# TODO(hw): remove after 2024.2.* is stable
186188
- ["mv", "build.gradle-latest.kts", "build.gradle.kts"]
187189
- - "bash"

components/ide/jetbrains/backend-plugin/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ project(":") {
4040
if (properties("platformType") == "RD") {
4141
print("Rider: exclude unnecessary files")
4242
sourceSets["main"].kotlin.exclude("**/GitpodForceUpdateMavenProjectsActivity.kt")
43+
sourceSets["main"].kotlin.exclude("**/GradleSyncListener.kt")
4344
sourceSets["main"].kotlin.exclude("**/maven.xml")
4445
}
4546
}

components/ide/jetbrains/backend-plugin/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pluginVersion=0.0.1
22
gitpodVersion=dev
33
# Supported environments: stable, latest (via https://github.com/stevesaliman/gradle-properties-plugin)
4-
environmentName=latest
4+
environmentName=stable
55
# IntelliJ Platform Artifacts Repositories
66
# -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
77
pluginGroup=io.gitpod.jetbrains
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 io.gitpod.jetbrains.remote.listeners
6+
7+
import com.intellij.notification.Notification
8+
import com.intellij.notification.NotificationAction
9+
import com.intellij.notification.NotificationType
10+
import com.intellij.notification.Notifications
11+
import com.intellij.openapi.actionSystem.AnActionEvent
12+
import com.intellij.openapi.application.ApplicationManager
13+
import com.intellij.openapi.diagnostic.thisLogger
14+
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
15+
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener
16+
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType
17+
import java.io.File
18+
19+
class GradleSyncListener : ExternalSystemTaskNotificationListener {
20+
override fun onStart(id: ExternalSystemTaskId, workingDir: String?) {
21+
if (id.projectSystemId.toString() != "GRADLE" || id.type != ExternalSystemTaskType.RESOLVE_PROJECT) {
22+
return
23+
}
24+
val lockFile = File("/tmp/gitpod-gradle.lock")
25+
if (!lockFile.exists()) {
26+
return
27+
}
28+
29+
val notification = Notification(
30+
"gitpod",
31+
"Gitpod: Pause gradle sync",
32+
"Pausing Gradle Sync, execute <code style='color: orange;'>gp jetbrains gradle resume</code> to unblock all builtin Gradle Sync <br><br>Current Task ID: ${id.id}",
33+
NotificationType.INFORMATION
34+
)
35+
var isCancelled = false
36+
notification.addAction(object : NotificationAction("Cancel") {
37+
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
38+
isCancelled = true
39+
notification.expire()
40+
}
41+
})
42+
Notifications.Bus.notify(notification)
43+
44+
while (lockFile.exists()) {
45+
if (isCancelled) {
46+
thisLogger().warn("gitpod: gradle sync pausing is cancelled")
47+
break
48+
}
49+
Thread.sleep(1000)
50+
}
51+
thisLogger().warn("gitpod: gradle sync pausing finished")
52+
ApplicationManager.getApplication().invokeLater {
53+
notification.expire()
54+
}
55+
}
56+
}

components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
<applicationService serviceInterface="io.gitpod.jetbrains.remote.GitpodIgnoredPortsForNotificationService"
5555
serviceImplementation="io.gitpod.jetbrains.remote.internal.GitpodIgnoredPortsForNotificationServiceImpl"
5656
preload="true"/>
57+
58+
<externalSystemTaskNotificationListener
59+
implementation="io.gitpod.jetbrains.remote.listeners.GradleSyncListener"/>
5760
</extensions>
5861

5962
<actions>

0 commit comments

Comments
 (0)