Skip to content

Commit 07327b3

Browse files
committed
backend-plugin
1 parent 29d364b commit 07327b3

File tree

1 file changed

+35
-42
lines changed
  • components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/listeners

1 file changed

+35
-42
lines changed

components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/listeners/GradleSyncListener.kt

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,53 @@
44

55
package io.gitpod.jetbrains.remote.listeners
66

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
713
import com.intellij.openapi.diagnostic.thisLogger
814
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
915
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener
10-
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter
1116
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType
12-
import com.intellij.openapi.progress.ProgressIndicator
13-
import com.intellij.openapi.progress.ProgressManager
14-
import com.intellij.openapi.progress.Task
15-
import kotlinx.coroutines.delay
16-
import java.util.concurrent.CompletableFuture
17-
import java.util.concurrent.TimeUnit
17+
import java.io.File
1818

1919
class GradleSyncListener : ExternalSystemTaskNotificationListener {
2020
override fun onStart(id: ExternalSystemTaskId, workingDir: String?) {
21-
thisLogger().warn("===========hwen.onStart.1 ${id.projectSystemId} ${id.type} ${workingDir}")
2221
if (id.projectSystemId.toString() != "GRADLE" || id.type != ExternalSystemTaskType.RESOLVE_PROJECT) {
2322
return
2423
}
25-
thisLogger().warn("===========hwen.onStart.2 gradle")
26-
27-
Thread.sleep(90000L)
28-
thisLogger().warn("===========hwen.onStart.3")
29-
30-
// 使用后台任务执行延迟
31-
ProgressManager.getInstance().run(
32-
object : Task.Backgroundable(null, "Waiting before Gradle sync", true) {
33-
override fun run(indicator: ProgressIndicator) {
34-
try {
35-
indicator.isIndeterminate = false
36-
37-
for (i in 1..10) {
38-
if (indicator.isCanceled) {
39-
thisLogger().warn("===========hwen.4 Delay was cancelled by user")
40-
return
41-
}
42-
43-
indicator.fraction = i / 10.0
44-
indicator.text = "Waiting ${10 - i} seconds before Gradle sync..."
45-
46-
CompletableFuture.delayedExecutor(1, TimeUnit.SECONDS)
47-
.execute {}.run { }
48-
}
24+
val lockFile = File("/tmp/gitpod-gradle.lock")
25+
if (!lockFile.exists()) {
26+
return
27+
}
4928

50-
thisLogger().warn("===========hwen.5 Delay completed, continuing with sync")
51-
} catch (e: Exception) {
52-
thisLogger().error("===========hwen.6 Error during delay", e)
53-
}
54-
}
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",
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)
5543

56-
override fun onCancel() {
57-
thisLogger().warn("==============hwen.7 Delay was cancelled")
58-
super.onCancel()
59-
}
44+
while (lockFile.exists()) {
45+
if (isCancelled) {
46+
thisLogger().warn("gitpod: gradle sync pausing is cancelled")
47+
break
6048
}
61-
)
49+
Thread.sleep(1000)
50+
}
51+
thisLogger().warn("gitpod: gradle sync pausing finished")
52+
ApplicationManager.getApplication().invokeLater {
53+
notification.expire()
54+
}
6255
}
6356
}

0 commit comments

Comments
 (0)